home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 9536 / 9536.xpi / chrome / commentsbar_ff.jar / content / commentsbar_ff / tb.js < prev    next >
Text File  |  2009-03-25  |  200KB  |  5,610 lines

  1. var commentsbar_ff_tool = new Object();
  2. commentsbar_ff_tool.Layout = 0;
  3. commentsbar_ff_tool.prevLayout = -1;
  4. commentsbar_ff_tool.guid = '{5A0035AB-8F83-4D03-BE4E-C8267A3A4A1A}';
  5. commentsbar_ff_tool.ver = '1.0.1';
  6. commentsbar_ff_tool.Var = new Array();
  7. commentsbar_ff_tool.SVar = new Array();
  8. commentsbar_ff_tool.userName = '';
  9. commentsbar_ff_tool.userPasswd = '';
  10.  
  11. commentsbar_ff_tool.AffiliateID = '';
  12.  
  13. commentsbar_ff_tool.userid = '';
  14. commentsbar_ff_tool.toolbarid = '';
  15. commentsbar_ff_tool.explorer = null;
  16. commentsbar_ff_tool.promoCode = "";
  17. commentsbar_ff_tool.firstlaunch = "1";
  18. commentsbar_ff_tool.firstrun = "1";
  19. commentsbar_ff_tool.ToolbarFace = "";
  20.  
  21. commentsbar_ff_tool.Font = "";
  22. commentsbar_ff_tool.FontSize = "";
  23.  
  24. var commentsbar_ff_rotool = new Object();
  25. commentsbar_ff_rotool.ver = commentsbar_ff_tool.ver;
  26. commentsbar_ff_rotool.guid = '';
  27. //set in init
  28. commentsbar_ff_rotool.popupBlockedCnt = 0;
  29.  
  30. //plugins//
  31. commentsbar_ff_rotool.autofill =0;
  32.  
  33. var commentsbar_ff_hot_icons =0;
  34.  
  35. var debugmode = 0;
  36.  
  37. commentsbar_ff_tool.cookie = '';
  38. commentsbar_ff_tool.document = document;
  39. commentsbar_ff_tool.window = window.self;
  40. commentsbar_ff_tool.url = "";
  41. commentsbar_ff_tool.title = "";
  42.  
  43. var currentdomain = '';
  44. var defenc = '';
  45.  
  46. function commentsbar_ff_redirect(url)
  47. {window._content.document.location=url;}
  48. commentsbar_ff_tool.redirect = commentsbar_ff_redirect;
  49.  
  50. function cbLog(e)
  51.     {
  52.     Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService).logStringMessage(e);
  53.     }
  54.  
  55. function commentsbar_ff_limit_text(id, num)
  56. {
  57.     try {
  58.         if (num == '' || num == null || num == "undefined") return;
  59.         var tb = document.getElementById(id);
  60.         var n = num * 1;
  61.         if (tb.value.length > n) tb.value = tb.value.substring(0, n);
  62.     } catch(e) {/*alert(e)*/
  63.     }
  64. }
  65.  
  66.  
  67. commentsbar_ff_tool.getCustomXML = function(sName) 
  68. {
  69.     for (var j = 0; j < commentsbar_ff_customXml.length; j++)
  70.     {
  71.         if (commentsbar_ff_customXml[j].name == '_custom_xml_' + sName) return commentsbar_ff_customXml[j].xmldata;
  72.     }
  73.     return '';
  74. }
  75.  
  76. function commentsbar_ff_combochange()
  77. {
  78.     try {
  79.         var empty = true;
  80.         var combos = document.getElementsByTagName("menulist");
  81.         var cmb_tmp;
  82.         for (i = 0; i < combos.length; i++)
  83.         {
  84.             cmb_tmp = combos.item(i);
  85.             if (cmb_tmp.value.length > 0) empty = false;
  86.         }
  87.  
  88.         var tb = document.getElementById('commentsbar_ff-toolbar');
  89.         var cmd = tb.getElementsByTagName('command');
  90.         for (var j = 0; j < cmd.length; j++)
  91.         {
  92.             if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();')
  93.                 if (empty) cmd.item(j).setAttribute('disabled', 'true');
  94.                 else cmd.item(j).setAttribute('disabled', 'false');
  95.  
  96.         }
  97.     } catch(e) {/*alert(e)*/
  98.     }
  99. }
  100.  
  101.  
  102. function commentsbar_ff_close_bubble()
  103. {
  104.     if (bubblewindow != 0 && bubblewindow.closed == false) {
  105.         bubblewindow.close();
  106.         return;
  107.     }
  108. }
  109. commentsbar_ff_tool.closeBubble = commentsbar_ff_close_bubble;
  110.  
  111.  
  112. function commentsbar_ff_update_history()
  113. {
  114.     commentsbar_ff_all_combo_update_history()
  115. }
  116. commentsbar_ff_tool.updateHistory = commentsbar_ff_update_history;
  117.  
  118.  
  119. function readcookies() {
  120.     try {
  121.         var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"]
  122.                 .getService(Components.interfaces.nsICookieManager);
  123.         var e = cookieMgr.enumerator;
  124.         var cookies = [];
  125.         while (e.hasMoreElements()) {
  126.             var cookie = e.getNext().QueryInterface(Components.interfaces.nsICookie);
  127.             cookies.push(cookie);
  128.         }
  129.         commentsbar_ff_tool.cookie = '';
  130.  
  131.         for (var i = 0; i < cookies.length; ++i) {
  132.             var temp = cookies[i].host.substring(1, cookies[i].host.length);
  133.  
  134.             if (currentdomain.indexOf(temp) != -1)
  135.             {
  136.                 if (commentsbar_ff_tool.cookie != '') commentsbar_ff_tool.cookie += ';';
  137.                 commentsbar_ff_tool.cookie += cookies[i].name + '=' + cookies[i].value;
  138.  
  139.             }
  140.         }
  141.     } catch(e) {
  142.         if (debugmode) cbLog(e);
  143.     }
  144. }
  145.  
  146.  
  147. var primaryurl = '';
  148. //setTimeout('commentsbar_ff_timer();', 60000);
  149. var commentsbar_ff_time = 0;
  150.  
  151. function commentsbar_ff_plugin_init()
  152. {
  153.     if (commentsbar_ff_rotool.autofill == 1)
  154.     {
  155.         commentsbar_ff_autofill_init();
  156.     }
  157. }
  158.  
  159. function commentsbar_ff_GetVariable(name)
  160. {
  161.     try {
  162.         var tmp;
  163.         name = name.replace(/[\#\\.]/g, '');
  164.         var saved_param = commentsbar_ff_load_pref("commentsbar_ff_tool.variable" + name, "");
  165.         if (saved_param)
  166.             tmp = saved_param;
  167.         else
  168.             eval('tmp=commentsbar_ff_tool.variable' + name + ';');
  169.         if (!tmp) tmp = '';
  170.         return tmp;
  171.     } catch(e) {
  172.         if (debugmode) cbLog(e);
  173.     }
  174. }
  175.  
  176. function commentsbar_ff_SetVariable(name, val)
  177. {
  178.     try {
  179.         name = name.replace(/[\#\\.]/g, '');
  180.         eval('commentsbar_ff_tool.variable' + name + '=\'' + val + '\';');
  181.         commentsbar_ff_pref("commentsbar_ff_tool.variable" + name, val.toString());
  182.     } catch(e) {
  183.         if (debugmode) cbLog(e);
  184.     }
  185. }
  186.  
  187. commentsbar_ff_tool.GetVariable = commentsbar_ff_GetVariable;
  188. commentsbar_ff_tool.SetVariable = commentsbar_ff_SetVariable;
  189.  
  190. function commentsbar_ff_GetContent()
  191. {
  192.     try {
  193.         return window._content.document.getElementsByTagName("BODY")[0].innerHTML;
  194.     } catch(e) {
  195.         if (debugmode) cbLog(e);
  196.     }
  197. }
  198. commentsbar_ff_tool.GetContent = commentsbar_ff_GetContent;
  199.  
  200. function commentsbar_ff_GetById(id)
  201. {
  202.     try {
  203.         return window._content.document.getElementById(id);
  204.     } catch(e) {
  205.         if (debugmode) cbLog(e);
  206.     }
  207. }
  208. commentsbar_ff_tool.getElementById = commentsbar_ff_GetById;
  209. commentsbar_ff_tool.getElementByID = commentsbar_ff_GetById;
  210.  
  211. function commentsbar_ff_GetByTagName(id)
  212. {
  213.     try {
  214.         return window._content.document.getElementsByTagName(id);
  215.     } catch(e) {
  216.         if (debugmode) cbLog(e);
  217.     }
  218. }
  219. commentsbar_ff_tool.getElementsByTagName = commentsbar_ff_GetByTagName;
  220.  
  221.  
  222. function commentsbar_ff_external_search(href)
  223. {
  224.     try {
  225.         var set_ext_search = document.getElementById('settings_external_search');
  226.         if (!set_ext_search) return;
  227.         var engines = set_ext_search.getAttribute('value');
  228.         if (!engines) return;
  229.         var mas_eng = engines.split('/***/');
  230.  
  231.         for (var i = 0; i < mas_eng.length; i++)
  232.         {
  233.             if (!mas_eng[i]) return;
  234.             var cur_engine = mas_eng[i].split(';');
  235.             //target;engine;param
  236.  
  237.  
  238.             var re = cur_engine[1];
  239.             re = re.replace(/\./g, '\.');
  240.             re = re.replace(/\*/g, '.*');
  241.             re = re.replace(/\?/g, '.?');
  242.  
  243.             var reg_exp = new RegExp(re);
  244.             if (href.match(reg_exp))
  245.             {
  246.                 reg_exp = new RegExp('.*' + cur_engine[2] + '([^\&]*).*');
  247.                 if (href.match(reg_exp))
  248.                 {
  249.                     var text = href.replace(reg_exp, "$1");
  250.                     var combo = document.getElementById(cur_engine[0]);
  251.                     if (combo)
  252.                     {
  253.                         try
  254.                         {
  255.                             var characterSet = window._content.document.characterSet;
  256.                             const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
  257.                                     .getService(Components.interfaces.nsITextToSubURI);
  258.                             text = textToSubURI.unEscapeURIForUI(characterSet, text);
  259.                         }
  260.                         catch(ex) {
  261.                         }
  262.                         combo.value = text;
  263.                         //.replace(/\+/g,' ');
  264.                     }
  265.                 }
  266.             }
  267.         }
  268.  
  269.     } catch(e) {
  270.         if (debugmode) cbLog(e);
  271.     }
  272. }
  273.  
  274. function commentsbar_ff_settings_allowpopups(remove)
  275. {
  276.     try {
  277.         var set_allowpopups = document.getElementById('settings_allowpopups');
  278.         if (set_allowpopups)
  279.         {
  280.             var ap = set_allowpopups.getAttribute('value');
  281.             if (ap)
  282.             {
  283.                 var ap_sites = ap.split(';');
  284.                 var ci;
  285.                 for (ci = 0; ci < ap_sites.length; ci++)
  286.                     if (ap_sites[ci])
  287.                     {
  288.                         var service = Components.classes['@mozilla.org/permissionmanager;1'].getService(Components.interfaces.nsIPermissionManager);
  289.                         var url = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL);
  290.  
  291.                         url.spec = ap_sites[ci];
  292.                         var isAllowed = service.testPermission(url, "popup");
  293.  
  294.                         if (isAllowed && remove == true)
  295.                         {
  296.                             host = url.spec;
  297.                             host = host.replace(/\/$/, '');
  298.                             service.remove(host, "popup");
  299.                         }
  300.                         else if (!isAllowed)
  301.                         {
  302.                             service.add(url, "popup", 1);
  303.                         }
  304.                     }
  305.             }
  306.         }
  307.     } catch(e) {
  308.         if (debugmode) cbLog(e);
  309.     }
  310. }
  311.  
  312. function commentsbar_ff_timer()
  313. {
  314.     try {
  315.         var tb = document.getElementById('commentsbar_ff-toolbar');
  316.         if (!tb) return;
  317.  
  318.         commentsbar_ff_time++;
  319.  
  320.         //manage include xml
  321.         var tb = document.getElementById('commentsbar_ff-toolbar');
  322.         var inc = tb.getElementsByTagName("box");
  323.         var i;
  324.         if (requests)
  325.         {
  326.             var cmb_tmp;
  327.             refresh_queue = new Array();
  328.             for (i = 0; i < inc.length; i++)
  329.             {
  330.                 cmb_tmp = inc.item(i);
  331.                 if (!cmb_tmp.getAttribute('filename') || !cmb_tmp.getAttribute('expire')) continue;
  332.                 if (commentsbar_ff_time % cmb_tmp.getAttribute('expire') == 0)
  333.                     refresh_queue.push(cmb_tmp.getAttribute('id'));
  334.             }
  335.             commentsbar_ff_expire_refresh_include_xml();
  336.         }
  337.  
  338.         //manage banner
  339.         var ban = tb.getElementsByTagName('iframe');
  340.         if (ban)
  341.         {
  342.             for (i = 0; i < ban.length; i++)
  343.             {
  344.                 if (!ban[i].getAttribute('expire')) continue;
  345.                 if (commentsbar_ff_time % ban[i].getAttribute('expire') == 0)
  346.                 {
  347.                     if (ban[i].getAttribute('bannertype') != 'script' && ban[i].webNavigation)
  348.                     //ban[i].webNavigation.reload(Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH);
  349.                         ban[i].webNavigation.loadURI(commentsbar_ff_macro_substitution_utf8(ban[i].getAttribute('url')),
  350.                                 Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null);
  351.                 }
  352.             }
  353.         }
  354.  
  355.         setTimeout('commentsbar_ff_timer();', 60000);
  356.     } catch(e) {
  357.         if (debugmode) cbLog(e);
  358.     }
  359. }
  360.  
  361. function commentsbar_ff_check_banner(e)
  362. {
  363.     try {
  364.         var title = e.originalTarget.title;
  365.         var loc = e.originalTarget.location;
  366.         var tb = document.getElementById('commentsbar_ff-toolbar');
  367.         var banners = tb.getElementsByTagName('iframe');
  368.         for (var i = 0; i < banners.length; i++)
  369.             if (banners.item(i).getAttribute('src') == loc) break;
  370.  
  371.         if (i == banners.length) return;
  372.  
  373.         var banner = banners.item(i);
  374.         if (title == '404 Not Found')
  375.         {
  376.             if (banner.getAttribute('bannertype') != 'script' && banner.getAttribute('local'))
  377.             {
  378.                 banner.removeEventListener("load", commentsbar_ff_check_banner, true);
  379.                 banner.setAttribute('src', 'chrome://commentsbar_ff/content/' + banner.getAttribute('local'));
  380.                 banner.webNavigation.loadURI('chrome://commentsbar_ff/content/' + banner.getAttribute('local'), Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null);
  381.                 banner.addEventListener("load", commentsbar_ff_check_banner, true);
  382.             }
  383.         }
  384.     } catch(e) {
  385.         if (debugmode) cbLog(e);
  386.     }
  387. }
  388.  
  389. function commentsbar_ff_refresh_banner(sync)
  390. {
  391.     try {
  392.         var tb = document.getElementById('commentsbar_ff-toolbar');
  393.         if (!tb || !window.toolbar.visible) return;
  394.         var ban = tb.getElementsByTagName('iframe');
  395.         if (ban)
  396.         {
  397.             for (var i = 0; i < ban.length; i++)
  398.             {
  399.                 //if (!ban[i].getAttribute('sync')) continue;
  400.                 if (ban[i].getAttribute('sync') == sync || ban[i].getAttribute('sync') == "both")// || (!ban[i].getAttribute('sync') && sync=='OnDocumentComplete'))
  401.                 {
  402.                     if (ban[i].getAttribute('bannertype') != 'script' && ban[i].webNavigation)
  403.                     {
  404.                         if (ban[i].getAttribute('url'))    ban[i].setAttribute('src', commentsbar_ff_macro_substitution_utf8(ban[i].getAttribute('url')));
  405.                         //ban[i].webNavigation.reload(Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH);
  406.                         if (ban[i].getAttribute('src') && ban[i].getAttribute('src') != '') ban[i].webNavigation.loadURI(commentsbar_ff_macro_substitution_utf8(ban[i].getAttribute('src')),
  407.                                 Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null);
  408.                     }
  409.                 }
  410.             }
  411.         }
  412.     init_script_commentsbar_ff(sync);
  413.     } catch(e) {
  414.         if (debugmode) cbLog(e);
  415.     }
  416. }
  417.  
  418. function commentsbar_ff_set_hot(id)
  419. {
  420.     try {
  421.         if (id == '') return;
  422.         var b = document.getElementById(id);
  423.         if (!b) return;
  424.         var tagimage;
  425.         var f = 0;
  426.         //0-attr; 1-tag
  427.         var img;
  428.         img = b.getAttribute('image');
  429.         if (!img)
  430.         {
  431.             tagimage = document.getElementById(id + '_img');
  432.             if (!tagimage) return;
  433.             img = tagimage.getAttribute('src');
  434.             if (!img) return;
  435.             f = 1;
  436.         }
  437.  
  438.         if (!b.getAttribute('hot_image'))    //icons
  439.         {
  440.             if (!commentsbar_ff_hot_icons) return;
  441.             img = img.replace(/img/, 'himg');
  442.             if (f)
  443.                 tagimage.setAttribute('src', img);
  444.             else
  445.                 b.setAttribute('image', img);
  446.         }
  447.         else
  448.         {
  449.             var himg = b.getAttribute('hot_image');
  450.             if (!himg) return;
  451.  
  452.             if (f)
  453.                 tagimage.setAttribute('src', himg);
  454.             else
  455.                 b.setAttribute('image', himg);
  456.  
  457.             b.setAttribute('hot_image', img);
  458.         }
  459.     } catch(e) {
  460.         if (debugmode) cbLog(e);
  461.     }
  462. }
  463.  
  464. function commentsbar_ff_set_nothot(id)
  465. {
  466.     try {
  467.         if (id == '') return;
  468.         var b = document.getElementById(id);
  469.         if (!b) return;
  470.         var tagimage;
  471.         var f = 0;
  472.         //0-attr; 1-tag
  473.         var img;
  474.         img = b.getAttribute('image');
  475.         if (!img)
  476.         {
  477.             tagimage = document.getElementById(id + '_img');
  478.             if (!tagimage) return;
  479.             img = tagimage.getAttribute('src');
  480.             if (!img) return;
  481.             f = 1;
  482.         }
  483.  
  484.         if (!b.getAttribute('hot_image'))    //icons
  485.         {
  486.             if (!commentsbar_ff_hot_icons) return;
  487.             img = img.replace(/himg/, 'img');
  488.             if (f)
  489.                 tagimage.setAttribute('src', img);
  490.             else
  491.                 b.setAttribute('image', img);
  492.         }
  493.         else
  494.         {
  495.             var himg = b.getAttribute('hot_image');
  496.             if (!himg) return;
  497.  
  498.             if (f)
  499.                 tagimage.setAttribute('src', himg);
  500.             else
  501.                 b.setAttribute('image', himg);
  502.  
  503.             b.setAttribute('hot_image', img);
  504.         }
  505.     } catch(e) {
  506.         if (debugmode) cbLog(e);
  507.     }
  508. }
  509.  
  510.  
  511. function commentsbar_ff_gen_toolbar_id()
  512. {
  513.     if (commentsbar_ff_getPref("commentsbar_ff.guid") == null)
  514.     {
  515.         var S = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
  516.         var id = '{';
  517.         for (i = 0; i < 8; i++)
  518.             id = id + S[Math.round(Math.random() * 15)];
  519.  
  520.         id = id + '-';
  521.         for (i = 0; i < 4; i++)
  522.             id = id + S[Math.round(Math.random() * 15)];
  523.  
  524.         id = id + '-';
  525.         for (i = 0; i < 4; i++)
  526.             id = id + S[Math.round(Math.random() * 15)];
  527.  
  528.         id = id + '-';
  529.         for (i = 0; i < 4; i++)
  530.             id = id + S[Math.round(Math.random() * 15)];
  531.  
  532.         id = id + '-';
  533.         for (i = 0; i < 12; i++)
  534.             id = id + S[Math.round(Math.random() * 15)];
  535.         id = id + '}';
  536.  
  537.         //commentsbar_ff_set_opt ('guid', id);
  538.         commentsbar_ff_pref("commentsbar_ff.guid", id);
  539.     }
  540.     //return commentsbar_ff_get_opt('guid');
  541.     return commentsbar_ff_getPref("commentsbar_ff.guid");
  542. }
  543.  
  544.  
  545. function commentsbar_ff_uninstall()
  546. {
  547.     //This function is never called - to be cleaned up later
  548.     return;
  549.     try {
  550.         var name = "toolbar";
  551.         var tb = document.getElementById('commentsbar_ff-toolbar');
  552.         if (tb && tb.toolbarName)
  553.             name = tb.toolbarName;
  554.         var text = "This will remove the " + name + " from your computer. Are you sure?";
  555.         var msg = document.getElementById("message_uninstallMsg");
  556.         if (msg)
  557.             text = msg.getAttribute('value');
  558.         if (!window.confirm(text))
  559.             return;
  560.         commentsbar_ff_pref('general.useragent.override', navigator.userAgent);
  561.         commentsbar_ff_clearPref('general.useragent.override');
  562.  
  563.         if (navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('BonEcho') != -1 || navigator.userAgent.indexOf('Minefield') != -1 || navigator.userAgent.indexOf('Netscape/8') != -1)
  564.         {
  565.             var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"]
  566.                     .getService(Components.interfaces.nsIExtensionManager);
  567.             var rds = gExtensionManager.datasource;
  568.             if (gExtensionManager.uninstallItem) gExtensionManager.uninstallItem(commentsbar_ff_tool.guid);
  569.             if (gExtensionManager.uninstallExtension) gExtensionManager.uninstallExtension(commentsbar_ff_tool.guid);
  570.  
  571.             for (var j = 0; j < commentsbar_ff_customXml.length; j++) commentsbar_ff_pref("commentsbar_ff.custom_xmls." + commentsbar_ff_customXml[j].name,"");
  572.         commentsbar_ff_pref("commentsbar_ff.custom_xmls", "");
  573.         commentsbar_ff_customXml = new Array();
  574.         for (i = 1; i <= 10; i++)
  575.         {
  576.             eval('commentsbar_ff_pref( "commentsbar_ff.Var' + i + '", "0")');
  577.             eval('commentsbar_ff_pref( "commentsbar_ff.SVar' + i + '", "0")');
  578.         }
  579.  
  580.  
  581.             commentsbar_ff_settings_allowpopups(true);
  582.             commentsbar_ff_clearhistory("");
  583.             commentsbar_ff_tool.firstlaunch = "1";
  584.             var uninstallURL = document.getElementById('url_urlAfterUninstall');
  585.             if (uninstallURL.getAttribute('value'))
  586.                 commentsbar_ff_webjump(uninstallURL.getAttribute('value'), "", "", "");
  587.             alert('Restart the browser.');
  588.         }
  589.         else
  590.         {
  591.             var uninstallURL = document.getElementById('url_urlAfterUninstall');
  592.             if (uninstallURL.getAttribute('value'))
  593.                 commentsbar_ff_webjump(uninstallURL.getAttribute('value'), "", "", "");
  594.             commentsbar_ff_clearhistory("");
  595.             commentsbar_ff_tool.firstlaunch = "1";
  596.  
  597.             try {
  598.                 jslibUninstall('untitled');
  599.             } catch(k)
  600.             {
  601.                 var str = "urn:mozilla:package:commentsbar_ff";
  602.                 oExtUninstall = new ExtensionUninstall(str);
  603.                 success = oExtUninstall.uninstall();
  604.             }
  605.             alert('Restart the browser.');
  606.         }
  607.     } catch(e) {
  608.         if (debugmode) cbLog(e);
  609.     }
  610. }
  611.  
  612. var commentsbar_ff_wnd;
  613.  
  614.  
  615. function commentsbar_ff_update()
  616. {
  617.     //AMO doesn't allow this,return to Firefox default - automatically check as per a ff pref
  618.     return;
  619.     try {
  620.         if (navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('BonEcho') != -1 || navigator.userAgent.indexOf('Minefield') != -1)
  621.         {
  622.             var id = commentsbar_ff_tool.guid;
  623.  
  624.             var itemType = Components.interfaces.nsIUpdateItem.TYPE_EXTENSION;
  625.             var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"]
  626.                     .getService(Components.interfaces.nsIExtensionManager);
  627.  
  628.             var items;
  629.             try {
  630.                 items = gExtensionManager.getItemList(id, itemType, { });
  631.                 var updates = Components.classes["@mozilla.org/updates/update-service;1"]
  632.                         .getService(Components.interfaces.nsIUpdateService);
  633.  
  634.                 updates.checkForUpdates(items, items.length, itemType, Components.interfaces.nsIUpdateService.SOURCE_EVENT_USER, window);
  635.             }
  636.             catch(e)
  637.             {
  638.                 BrowserOpenExtensions('extensions');
  639.                 items = [gExtensionManager.getItemForID(id)];
  640.                 gExtensionManager.update(items, items.length, false, null);
  641.             }
  642.         }
  643.     } catch(e) {
  644.         try {
  645.             const EMTYPE = "Extension:Manager";
  646.             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  647.                     .getService(Components.interfaces.nsIWindowMediator);
  648.             var theEM = wm.getMostRecentWindow(EMTYPE);
  649.             if (theEM) {
  650.                 theEM.focus();
  651.                 return;
  652.             }
  653.             const EMURL = "chrome://mozapps/content/extensions/extensions.xul";
  654.             const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable";
  655.             commentsbar_ff_wnd = 0;
  656.             commentsbar_ff_wnd = window.openDialog(EMURL, "", EMFEATURES);
  657.  
  658.             setTimeout('postupdate();', 250);
  659.             return;
  660.         } catch(e) {
  661.         }
  662.     }
  663. }
  664.  
  665. function postupdate()
  666. {
  667.     try
  668.     {
  669.         if (commentsbar_ff_wnd == 0) {
  670.             setTimeout('postupdate();', 250);
  671.             return;
  672.         }
  673.         var item = commentsbar_ff_wnd.document.getElementById('checkUpdatesAllButton');
  674.         item.doCommand();
  675.     } catch(e) {
  676.     }
  677. }
  678.  
  679.  
  680. // HIGHLIGHT
  681.  
  682. var commentsbar_ff_highlight_colours = new Array();
  683. commentsbar_ff_highlight_colours.push('rgb(246, 255, 0)');
  684. commentsbar_ff_highlight_colours.push('rgb(0, 255, 228)');
  685. commentsbar_ff_highlight_colours.push('rgb(90, 255, 0)');
  686. commentsbar_ff_highlight_colours.push('rgb(0, 135, 255)');
  687. commentsbar_ff_highlight_colours.push('rgb(255, 204, 0)');
  688. commentsbar_ff_highlight_colours.push('rgb(255, 0, 240)');
  689.  
  690. function commentsbar_ff_load_highlight_colors()
  691. {
  692.     try {
  693.         var set = document.getElementById('settings_highlight');
  694.         if (!set) return;
  695.         var c = set.getAttribute('colors');
  696.         var colors = c.split(';');
  697.  
  698.         colors.pop();
  699.  
  700.         commentsbar_ff_highlight_colours = new Array();
  701.         for (i = 0; i < colors.length; i++)
  702.             commentsbar_ff_highlight_colours[i] = colors[i];
  703.     } catch(e) {
  704.         if (debugmode) cbLog(e);
  705.     }
  706. }
  707.  
  708. function commentsbar_ff_rgb_to_hex(rgb)
  709. {
  710.     var c = "#";
  711.     try {
  712.         if (rgb == '')
  713.             return c;
  714.         rgb = rgb.split(',');
  715.         if (rgb.length < 3)
  716.             return c;
  717.         c += commentsbar_ff_toHex(rgb[0]);
  718.         c += commentsbar_ff_toHex(rgb[1]);
  719.         c += commentsbar_ff_toHex(rgb[2]);
  720.     } catch(e) {
  721.         if (debugmode) cbLog(e);
  722.     }
  723.     return c;
  724. }
  725.  
  726. function commentsbar_ff_menu_active(e)
  727. {
  728.     try {
  729.         if ((e.type == "mouseover" || e.type == "focus"))
  730.         {
  731.             if (e.target.hasAttribute('menu_style_over'))
  732.                 e.target.setAttribute('style', e.target.getAttribute('menu_style_over'));
  733.         }
  734.         else
  735.         {
  736.             if (e.target.hasAttribute('menu_style_out'))
  737.                 e.target.setAttribute('style', e.target.getAttribute('menu_style_out'));
  738.         }
  739.     } catch(e) {
  740.         if (debugmode) cbLog(e);
  741.     }
  742. }
  743.  
  744. function commentsbar_ff_color_schema()
  745. {
  746.     try {
  747.         var tb = document.getElementById('commentsbar_ff-toolbar');
  748.         tb.setAttribute('style', "max-height:20pt");
  749.         var schm = document.getElementById('color_schema');
  750.         if (!schm || !tb)
  751.             return;
  752.         //load toolbar styles
  753.         var bBackground = false;
  754.         var tb_skin = schm.getAttribute('toolbar_skin');
  755.         if (tb_skin != '' && tb.parentNode && tb.parentNode.style)
  756.         {
  757.             var parStyle = tb.parentNode.getAttribute('style');
  758.             parStyle += 'background-image:url("' + tb_skin + '");';
  759.             tb.parentNode.setAttribute('style', parStyle);
  760.             bBackground = true;
  761.         }
  762.  
  763.         var style = tb.getAttribute('style');
  764.  
  765.         var tbf = commentsbar_ff_rgb_to_hex(schm.getAttribute('toolbar_face'));
  766.         if (!bBackground && tbf != '#')
  767.             style += "background-color:" + tbf + ";";
  768.  
  769.         tb.setAttribute('style', style);
  770.  
  771.         //load menus styles
  772.         var menu_item = commentsbar_ff_rgb_to_hex(schm.getAttribute('menu'));
  773.         var menu_sel = commentsbar_ff_rgb_to_hex(schm.getAttribute('selected_menu_item'));
  774.         var menu_text = commentsbar_ff_rgb_to_hex(schm.getAttribute('text'));
  775.         var menu_sel_text = commentsbar_ff_rgb_to_hex(schm.getAttribute('highlight_text'));
  776.         var menus = tb.getElementsByTagName("menuitem");
  777.         for (var i = 0; i < menus.length; i++)
  778.             commentsbar_ff_apply_menu_style(menus[i], menu_item, menu_text, menu_sel, menu_sel_text);
  779.         menus = tb.getElementsByTagName("menu");
  780.         for (var i = 0; i < menus.length; i++)
  781.             commentsbar_ff_apply_menu_style(menus[i], menu_item, menu_text, menu_sel, menu_sel_text);
  782.     } catch(e) {
  783.         if (debugmode) cbLog(e);
  784.     }
  785. }
  786.  
  787. function commentsbar_ff_apply_menu_style(menu, menu_item, menu_text, menu_sel, menu_sel_text)
  788. {
  789.     try {
  790.         var menu_style_out = menu.getAttribute('style');
  791.         if (menu_text != '#')
  792.             menu_style_out += "color:" + menu_text + ";";
  793.         var menu_style_over = menu_style_out;
  794.         if (menu_item != '#')
  795.             menu_style_out += "background-color:" + menu_item + ";";
  796.         if (menu_sel != '#')
  797.             menu_style_over += "background-color:" + menu_sel + ";";
  798.         if (menu_sel_text != '#')
  799.             menu_style_over += "color:" + menu_sel_text + ";";
  800.         menu.setAttribute('menu_style_out', menu_style_out);
  801.         menu.setAttribute('menu_style_over', menu_style_over);
  802.         menu.setAttribute('style', menu_style_out);
  803.         menu.addEventListener('mouseover', commentsbar_ff_menu_active, true);
  804.         menu.addEventListener('mouseout', commentsbar_ff_menu_active, true);
  805.     } catch(e) {
  806.         if (debugmode) cbLog(e);
  807.     }
  808. }
  809.  
  810. function commentsbar_ff_get_input_terms()
  811. {
  812.     var i, j, k, quot, t, terms = new Array();
  813.  
  814.     var tb = document.getElementById('commentsbar_ff-toolbar');
  815.     var combos = tb.getElementsByTagName("menulist");
  816.  
  817.     for (var i = 0; i < combos.length; i++)
  818.     {
  819.         var quot1 = combos[i].value;
  820.         if (!quot1 || quot1 == 'undefined') continue;
  821.         if (quot1 == combos[i].getAttribute("text") || quot1 == combos[i].getAttribute("ptext")) continue;
  822.  
  823.         quot = quot1.split('"');
  824.         for (var j = 0; j < quot.length; j++)
  825.         {
  826.             if (j % 2)
  827.             {
  828.                 if (quot[j] != '') terms.push(quot[j]);
  829.             }
  830.             else
  831.             {
  832.                 t = quot[j].split(' ');
  833.                 for (var k = 0; k < t.length; k++)
  834.                 {
  835.                     if (t[k] != '') terms.push(t[k]);
  836.                 }
  837.             }
  838.         }
  839.     }
  840.  
  841.     var combos = tb.getElementsByTagName("textbox");
  842.  
  843.     for (var i = 0; i < combos.length; i++)
  844.     {
  845.         var quot1 = combos[i].value;
  846.         if (!quot1 || quot1 == 'undefined') continue;
  847.         if (quot1 == combos[i].getAttribute("text") || quot1 == combos[i].getAttribute("ptext")) continue;
  848.  
  849.         quot = quot1.split('"');
  850.         for (var j = 0; j < quot.length; j++)
  851.         {
  852.             if (j % 2)
  853.             {
  854.                 if (quot[j] != '') terms.push(quot[j]);
  855.             }
  856.             else
  857.             {
  858.                 t = quot[j].split(' ');
  859.                 for (var k = 0; k < t.length; k++)
  860.                 {
  861.                     if (t[k] != '') terms.push(t[k]);
  862.                 }
  863.             }
  864.         }
  865.     }
  866.  
  867.  
  868.     return terms;
  869. }
  870.  
  871.  
  872. function highlightRange(range, color, id)
  873. {
  874.     var startContainer = range.startContainer;
  875.     var spanNode = startContainer.ownerDocument.createElement("layer");
  876.     if (color.length < 7) color = '#' + color;
  877.     spanNode.style.backgroundColor = color;
  878.     spanNode.style.color = "black";
  879.     spanNode.id = id;
  880.     var docfrag = range.extractContents();
  881.     spanNode.appendChild(docfrag);
  882.     range.insertNode(spanNode);
  883.     return spanNode
  884. }
  885.  
  886.  
  887. function isWordCharacter(ch)
  888. {
  889.     if (ch == null || typeof ch != "string" || ch.length != 1) {
  890.         return false
  891.     }
  892.     var code = ch.charCodeAt(0);
  893.     return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 138 && code <= 142 || code >= 154 && code <= 159 || code >= 192 && code <= 255
  894. }
  895.  
  896. function isNodeInputNodeOrChildOf(node)
  897. {
  898.     if (node.nodeName.toUpperCase() == "INPUT") {
  899.         return true
  900.     }
  901.     if (node.parentNode != null) {
  902.         return isNodeInputNodeOrChildOf(node.parentNode)
  903.     }
  904.     return false
  905. }
  906.  
  907.  
  908. function commentsbar_ff_Highlight_aux(win, word, colour)
  909. {
  910.     try {
  911.         var set1, f;
  912.         for (f = 0; f < win.frames.length; f++) {
  913.             commentsbar_ff_Highlight_aux(win.frames[f], word, colour);
  914.         }
  915.         var doc = win.document;
  916.         if (doc != null) {
  917.             var body = doc.body;
  918.             if (body != null) {
  919.                 var docRange = doc.createRange();
  920.                 docRange.selectNode(body);
  921.                 var startRange = docRange.cloneRange();
  922.                 startRange.collapse(true);
  923.                 var stopRange = docRange.cloneRange();
  924.                 stopRange.collapse(false);
  925.                 var findRange = Components.classes["@mozilla.org/embedcomp/rangefind;1"].createInstance();
  926.                 if (findRange != null && findRange  instanceof Components.interfaces.nsIFind) {
  927.                     findRange.caseSensitive = false;
  928.                     findRange.findBackwards = false;
  929.                     var result = findRange.Find(word, docRange, startRange, stopRange);
  930.                     while (null != result) {
  931.                         if (result.endContainer != null && result.startContainer != null && result.endContainer.nodeType == Node.TEXT_NODE && result.startContainer.nodeType == Node.TEXT_NODE && ! isNodeInputNodeOrChildOf(result.startContainer) && ! isNodeInputNodeOrChildOf(result.endContainer)) {
  932.                             var startChar = null;
  933.                             if (result.startOffset > 0) {
  934.                                 startChar = result.startContainer.nodeValue.charAt(result.startOffset - 1)
  935.                             }
  936.                             var endChar = result.endContainer.nodeValue.charAt(result.endOffset);
  937.                             if (1)// ! isWordCharacter(startChar) &&  ! isWordCharacter(endChar))
  938.                             {
  939.                                 var spanNode = highlightRange(result, colour, "toolbar-highlight");
  940.                                 startRange.selectNode(spanNode);
  941.                             }
  942.                             else {
  943.                                 startRange = result
  944.                             }
  945.                         }
  946.                         else {
  947.                             startRange = result
  948.                         }
  949.                         startRange.collapse(false);
  950.                         result = findRange.Find(word, docRange, startRange, stopRange)
  951.                     }
  952.                 }
  953.             }
  954.         }
  955.  
  956.     } catch(e) {
  957.         if (debugmode) cbLog(e);
  958.     }
  959. }
  960.  
  961. function commentsbar_ff_Highlight_aux_undo(win)
  962. {
  963.     var result = false;
  964.     if (win != null) {
  965.         var doc = win.document;
  966.         if (win.frames != null) {
  967.             for (var i = 0; i < win.frames.length; i ++) {
  968.                 if (commentsbar_ff_Highlight_aux_undo(win.frames[i])) {
  969.                     result = true
  970.                 }
  971.             }
  972.         }
  973.         if (! result) {
  974.             var layer = doc.getElementById("toolbar-highlight");
  975.             while (layer != null) {
  976.                 var parent = layer.parentNode;
  977.                 var children = layer.childNodes;
  978.                 for (var index = children.length - 1; index >= 0; index --) {
  979.                     parent.insertBefore(children[0], layer)
  980.                 }
  981.                 parent.removeChild(layer);
  982.                 result = true;
  983.                 layer = doc.getElementById("toolbar-highlight")
  984.             }
  985.         }
  986.     }
  987.     return result
  988. }
  989.  
  990.  
  991. //function commentsbar_ff_Highlight_aux (win, word, colour)
  992. //{
  993. //    var set1, f;
  994. //    for (f = 0; f < win.frames.length; f++) {
  995. //        commentsbar_ff_Highlight_aux (win.frames[f], word, colour);
  996. /*
  997.         set1 = win.frames[f].document.body.innerHTML.split('<');
  998.         for (i in set1)
  999.         {
  1000.             set2 = set1[i].split('>');
  1001.             if (set2.length > 1)
  1002.             {
  1003.                 eval("set2[1] = set2[1].replace('"+word+"', '<layer id=\"toolbar-highlight\" style=\"background-color:#' + colour + ';color: rgb(0,0,0);\">"+word+"</layer>')");
  1004.                 var str=word[0].toUpperCase();
  1005.         word2=word.substring(1,word.length);
  1006.         word2=str+word2;
  1007.                 eval("set2[1] = set2[1].replace('"+word2+"', '<layer id=\"toolbar-highlight\" style=\"background-color:#' + colour + ';color: rgb(0,0,0);\">"+word2+"</layer>')");
  1008.             }
  1009.             set1[i] = set2.join('>');
  1010.         }
  1011.  
  1012.         win.frames[f].document.body.innerHTML = set1.join('<');
  1013.     }
  1014. }
  1015. */
  1016. var prev_commentsbar_ff_Highlight = new Array();
  1017.  
  1018. function commentsbar_ff_Highlight()
  1019. {
  1020.     try {
  1021.         var i, changed = 1;
  1022.         var colours = commentsbar_ff_highlight_colours;
  1023.         var terms = commentsbar_ff_get_input_terms(), prev = prev_commentsbar_ff_Highlight;
  1024.  
  1025.         if (terms.length == prev.length)
  1026.         {
  1027.             changed = 0;
  1028.             for (var i = 0; i < terms.length; i++)
  1029.             {
  1030.                 if (terms[i] != prev[i]) changed = 1;
  1031.             }
  1032.         }
  1033.  
  1034.         if (!changed)
  1035.         {
  1036.             for (var i = 0; i < prev.length; i++)
  1037.             {
  1038.                 //            commentsbar_ff_Highlight_aux_undo (window.self, prev[i], colours[i % colours.length]);
  1039.                 var tb = document.getElementById('commentsbar_ff-toolbar');
  1040.                 var cmd = tb.getElementsByTagName('command');
  1041.                 for (var j = 0; j < cmd.length; j++)
  1042.                 {
  1043.                     if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();') cmd.item(j).setAttribute('checked', 'false');
  1044.                 }
  1045.  
  1046.                 var tabBrowser = document.getElementById("content");
  1047.                 commentsbar_ff_Highlight_aux_undo(tabBrowser.selectedBrowser.contentWindow);
  1048.             }
  1049.             prev_commentsbar_ff_Highlight = new Array();
  1050.         }
  1051.         else
  1052.         {
  1053.             var tb = document.getElementById('commentsbar_ff-toolbar');
  1054.             var cmd = tb.getElementsByTagName('command');
  1055.             for (var j = 0; j < cmd.length; j++)
  1056.             {
  1057.                 if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();') cmd.item(j).setAttribute('checked', 'true');
  1058.             }
  1059.  
  1060.             for (var i = 0; i < prev.length; i++)
  1061.             {
  1062.                 //            commentsbar_ff_Highlight_aux_undo (window.self, prev[i], colours[i % colours.length]);
  1063.                 var tabBrowser = document.getElementById("content");
  1064.                 commentsbar_ff_Highlight_aux_undo(tabBrowser.selectedBrowser.contentWindow);
  1065.             }
  1066.             for (var i = 0; i < terms.length; i++)
  1067.             {
  1068.                 //            commentsbar_ff_Highlight_aux (window.self, terms[i], colours[i % colours.length]);
  1069.                 var tabBrowser = document.getElementById("content");
  1070.                 commentsbar_ff_Highlight_aux(tabBrowser.selectedBrowser.contentWindow, terms[i], colours[i % colours.length]);
  1071.             }
  1072.             prev_commentsbar_ff_Highlight = terms;
  1073.         }
  1074.     } catch(e) {
  1075.         if (debugmode) cbLog(e);
  1076.     }
  1077. }
  1078.  
  1079. ////////////
  1080.  
  1081. function commentsbar_ff_allowPopups()
  1082. {
  1083.     try {
  1084.         var service = Components.classes['@mozilla.org/permissionmanager;1'].getService(Components.interfaces.nsIPermissionManager);
  1085.         var url = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL);
  1086.  
  1087.         if (window._content.document.location.href == 'about:blank') return;
  1088.  
  1089.         url.spec = window._content.document.location.host;
  1090.         var isAllowed = service.testPermission(url, "popup");
  1091.  
  1092.         if (isAllowed)
  1093.         {
  1094.             host = url.spec;
  1095.             host = host.replace(/\/$/, '');
  1096.             service.remove(host, "popup");
  1097.         }
  1098.         else
  1099.         {
  1100.             service.add(url, "popup", 1);
  1101.         }
  1102.         commentsbar_ff_allowPopupsCheck();
  1103.     }
  1104.     catch(e) {
  1105.         if (debugmode) cbLog(e);
  1106.     }
  1107. }
  1108.  
  1109.  
  1110. function commentsbar_ff_allowPopupsCheck()
  1111. {
  1112.     try {
  1113.         var service = Components.classes['@mozilla.org/permissionmanager;1'].getService(Components.interfaces.nsIPermissionManager);
  1114.         var url = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL);
  1115.  
  1116.         if (window._content.document.location.href == 'about:blank') return;
  1117.  
  1118.         url.spec = window._content.document.location.host;
  1119.         var isAllowed = service.testPermission(url, "popup");
  1120.  
  1121.         var tags = new Array('toolbarbutton');
  1122.  
  1123.         for (var k = 0; k < tags.length; k++)
  1124.         {
  1125.             var tb = document.getElementById('commentsbar_ff-toolbar');
  1126.             var buttons = tb.getElementsByTagName(tags[k]);
  1127.             var b_tmp, c_tmp, cmd, oncmd;
  1128.  
  1129.             for (i = 0; i < buttons.length; i++)
  1130.             {
  1131.                 b_tmp = buttons.item(i);
  1132.                 c_tmp = b_tmp.getAttribute('command');
  1133.                 if (c_tmp && c_tmp != 'undefined' && c_tmp != null && c_tmp != "cmd_")
  1134.                 {
  1135.                     cmd = document.getElementById(c_tmp);
  1136.                     if (!cmd) continue;
  1137.                     oncmd = cmd.getAttribute('oncommand');
  1138.                     if (oncmd == 'commentsbar_ff_allowPopups();')
  1139.                     {
  1140.                         if (isAllowed == 1) b_tmp.setAttribute('checked', "true");
  1141.                         else b_tmp.setAttribute('checked', "false");
  1142.  
  1143.  
  1144.                         if (isAllowed) {
  1145.                             if (b_tmp.getAttribute('plabel'))
  1146.                             {
  1147.                                 var l = b_tmp.getAttribute('plabel');
  1148.                                 l = l.replace("#cnt#", commentsbar_ff_rotool.popupBlockedCnt);
  1149.                                 b_tmp.setAttribute('label', l);
  1150.                             }
  1151.                             if (b_tmp.getAttribute('rimage'))
  1152.                             {
  1153.                                 b_tmp.setAttribute('oimage', b_tmp.getAttribute('image'));
  1154.                                 b_tmp.setAttribute('image', b_tmp.getAttribute('rimage'));
  1155.                             }
  1156.                         }
  1157.                         else
  1158.                         {
  1159.                             commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0");
  1160.                             var l = b_tmp.getAttribute('rlabel');
  1161.                             l = l.replace("#cnt#", commentsbar_ff_rotool.popupBlockedCnt);
  1162.  
  1163.                             b_tmp.setAttribute('label', l);
  1164.                             if (b_tmp.getAttribute('oimage'))
  1165.                                 b_tmp.setAttribute('image', b_tmp.getAttribute('oimage'));
  1166.                         }
  1167.                     }
  1168.                 }
  1169.             }
  1170.         }
  1171.  
  1172.     }
  1173.     catch(e) {
  1174.         if (debugmode) cbLog(e);
  1175.     }
  1176.  
  1177. }
  1178.  
  1179.  
  1180. function commentsbar_ff_allowPopupsCount()
  1181. {
  1182.     try {
  1183.         if (window._content.document.location.href == 'about:blank') return;
  1184.  
  1185.         var tags = new Array('toolbarbutton');
  1186.  
  1187.         for (var k = 0; k < tags.length; k++)
  1188.         {
  1189.             var tb = document.getElementById('commentsbar_ff-toolbar');
  1190.             var buttons = tb.getElementsByTagName(tags[k]);
  1191.             var b_tmp, c_tmp, cmd, oncmd;
  1192.  
  1193.             for (var i = 0; i < buttons.length; i++)
  1194.             {
  1195.                 b_tmp = buttons.item(i);
  1196.                 c_tmp = b_tmp.getAttribute('command');
  1197.                 if (c_tmp && c_tmp != 'undefined' && c_tmp != null)
  1198.                 {
  1199.                     cmd = document.getElementById(c_tmp);
  1200.  
  1201.                     if (!cmd) continue;
  1202.                     oncmd = cmd.getAttribute('oncommand');
  1203.                     if (oncmd == 'commentsbar_ff_allowPopups();') commentsbar_ff_clearcount();
  1204.                 }
  1205.             }
  1206.         }
  1207.     }
  1208.     catch(e) {
  1209.         if (debugmode) cbLog(e);
  1210.     }
  1211.  
  1212. }
  1213.  
  1214.  
  1215. function commentsbar_ff_blockPopups()
  1216. {
  1217.     try {
  1218.         var pref = 'dom.disable_open_during_load';
  1219.         var p = navigator.preference(pref);
  1220.         navigator.preference(pref, !p);
  1221.  
  1222.         var tags = new Array('toolbarbutton', 'menuitem');
  1223.  
  1224.         for (var k = 0; k < tags.length; k++)
  1225.         {
  1226.             var tb = document.getElementById('commentsbar_ff-toolbar');
  1227.             var buttons = tb.getElementsByTagName(tags[k]);
  1228.             var b_tmp, c_tmp, cmd, oncmd;
  1229.  
  1230.             for (i = 0; i < buttons.length; i++)
  1231.             {
  1232.                 b_tmp = buttons.item(i);
  1233.                 c_tmp = b_tmp.getAttribute('command');
  1234.                 if (c_tmp && c_tmp != 'undefined' && c_tmp != null)
  1235.                 {
  1236.                     cmd = document.getElementById(c_tmp);
  1237.                     if (!cmd) continue;
  1238.                     oncmd = cmd.getAttribute('oncommand');
  1239.                     if (oncmd == 'commentsbar_ff_blockPopups();')
  1240.                         b_tmp.setAttribute('checked', !p);
  1241.                     if (!p)
  1242.                     {
  1243.                         if (b_tmp.getAttribute('plabel'))
  1244.                         {
  1245.                             var l = b_tmp.getAttribute('plabel');
  1246.                             //b_tmp.setAttribute('olabel', b_tmp.getAttribute('label'));
  1247.                             b_tmp.setAttribute('label', l.replace(/#cnt#/, commentsbar_ff_rotool.popupBlockedCnt));
  1248.                         }
  1249.                         if (b_tmp.getAttribute('rimage'))
  1250.                         {
  1251.                             b_tmp.setAttribute('oimage', b_tmp.getAttribute('image'));
  1252.                             b_tmp.setAttribute('image', b_tmp.getAttribute('rimage'));
  1253.                         }
  1254.                     }
  1255.                     else
  1256.                     {
  1257.                         commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0");
  1258.                         //if (b_tmp.getAttribute('olabel'))
  1259.                         b_tmp.setAttribute('label', b_tmp.getAttribute('rlabel'));
  1260.                         if (b_tmp.getAttribute('oimage'))
  1261.                             b_tmp.setAttribute('image', b_tmp.getAttribute('oimage'));
  1262.                     }
  1263.                 }
  1264.             }
  1265.         }
  1266.     } catch(e) {
  1267.         if (debugmode) cbLog(e);
  1268.     }
  1269. }
  1270.  
  1271. function commentsbar_ff_blockPopupsInit()
  1272. {
  1273.     try {
  1274.         var pref = 'dom.disable_open_during_load';
  1275.         var p = navigator.preference(pref);
  1276.         var tags = new Array('toolbarbutton', 'menuitem');
  1277.         for (var k = 0; k < tags.length; k++)
  1278.         {
  1279.             var tb = document.getElementById('commentsbar_ff-toolbar');
  1280.             var buttons = tb.getElementsByTagName(tags[k]);
  1281.             for (i = 0; i < buttons.length; i++)
  1282.             {
  1283.                 var b_tmp = buttons.item(i);
  1284.                 if (p)
  1285.                 {
  1286.                     if (b_tmp.getAttribute('plabel'))
  1287.                     {
  1288.                         var l = b_tmp.getAttribute('plabel');
  1289.                         b_tmp.setAttribute('label', l.replace(/#cnt#/, commentsbar_ff_rotool.popupBlockedCnt));
  1290.                     }
  1291.                     if (b_tmp.getAttribute('rimage'))
  1292.                     {
  1293.                         b_tmp.setAttribute('oimage', b_tmp.getAttribute('image'));
  1294.                         b_tmp.setAttribute('image', b_tmp.getAttribute('rimage'));
  1295.                     }
  1296.                     var c_tmp = b_tmp.getAttribute('command');
  1297.                     if (c_tmp && c_tmp != 'undefined' && c_tmp != null)
  1298.                     {
  1299.                         var cmd = document.getElementById(c_tmp);
  1300.                         if (!cmd) continue;
  1301.                         var oncmd = cmd.getAttribute('oncommand');
  1302.                         if (oncmd == 'commentsbar_ff_blockPopups();')
  1303.                             b_tmp.setAttribute('checked', p);
  1304.                     }
  1305.                 }
  1306.                 else
  1307.                 {
  1308.                     commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0");
  1309.                     b_tmp.setAttribute('label', b_tmp.getAttribute('rlabel'));
  1310.                     if (b_tmp.getAttribute('oimage'))
  1311.                         b_tmp.setAttribute('image', b_tmp.getAttribute('oimage'));
  1312.                 }
  1313.             }
  1314.         }
  1315.     } catch(e) {
  1316.         if (debugmode) cbLog(e);
  1317.     }
  1318. }
  1319.  
  1320. function commentsbar_ff_clearcount()
  1321. {
  1322.     commentsbar_ff_rotool.popupBlockedCnt = 0;
  1323.     commentsbar_ff_pref("commentsbar_ff.popupblockedcnt", commentsbar_ff_rotool.popupBlockedCnt.toString());
  1324.     commentsbar_ff_update_popup_cnt();
  1325. }
  1326.  
  1327.  
  1328. function commentsbar_ff_clearclipboard(message)
  1329. {
  1330.     try {
  1331.         if (!message || message == '' || confirm(message))
  1332.         {
  1333.             cb = Components.classes["@mozilla.org/widget/clipboard;1"]
  1334.                     .getService(Components.interfaces.nsIClipboard);
  1335.             cb.emptyClipboard(Components.interfaces.nsIClipboard.kGlobalClipboard);
  1336.         }
  1337.     } catch(e) {
  1338.         if (debugmode) cbLog(e);
  1339.     }
  1340. }
  1341.  
  1342. function commentsbar_ff_clearurlbarhistory(message)
  1343. {
  1344.     try {
  1345.         /*    if (!message || message == '' || confirm(message))
  1346.             {
  1347.                 var urlbarhist = Components.classes["@mozilla.org/browser/urlbarhistory;1"]
  1348.                                          .getService(Components.interfaces.nsIUrlbarHistory);
  1349.                 urlbarhist.clearHistory();
  1350.             }
  1351.         */
  1352.     } catch(e) {
  1353.         if (debugmode) cbLog(e);
  1354.     }
  1355. }
  1356.  
  1357. function commentsbar_ff_clearcookie(message)
  1358. {
  1359.     if (!message || message == '' || confirm(message))
  1360.     {
  1361.         var cookiemanager = Components.classes["@mozilla.org/cookiemanager;1"]
  1362.                 .getService(Components.interfaces.nsICookieManager);
  1363.         cookiemanager.removeAll();
  1364.     }
  1365. }
  1366.  
  1367. function commentsbar_ff_clearcache(message)
  1368. {
  1369.     if (!message || message == '' || confirm(message))
  1370.     {
  1371.         var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
  1372.                 .getService(Components.interfaces.nsICacheService);
  1373.         cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE);
  1374.     }
  1375. }
  1376.  
  1377. function commentsbar_ff_cleariehistory(message)
  1378. {
  1379.     if (!message || message == '' || confirm(message))
  1380.     {
  1381.         var globalHistory = Components.classes['@mozilla.org/browser/global-history;2']
  1382.                 .getService(Components.interfaces.nsIBrowserHistory);
  1383.         globalHistory.removeAllPages();
  1384.     }
  1385. }
  1386.  
  1387. function commentsbar_ff_clearautofill(message)
  1388. {
  1389.     if (!message || message == '' || confirm(message))
  1390.     {
  1391.         var formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
  1392.                 .getService(Components.interfaces.nsIFormHistory);
  1393.         formHistory.removeAllEntries();
  1394.     }
  1395. }
  1396. //COMBO
  1397. //update from onLocationChange
  1398.  
  1399. function commentsbar_ff_clearhistory(message)
  1400. {
  1401.     if (!(!message || message == '' || confirm(message))) return;
  1402.     var combos = document.getElementsByTagName("menulist");
  1403.     var cmb_tmp;
  1404.     for (i = 0; i < combos.length; i++)
  1405.     {
  1406.         cmb_tmp = combos.item(i);
  1407.         if (cmb_tmp.getAttribute('editable') == 'true')
  1408.         {
  1409.             cmb_tmp.removeAllItems();
  1410.             commentsbar_ff_pref("commentsbar_ff.stored_history" + cmb_tmp.getAttribute('id'), '');
  1411.         }
  1412.         cmb_tmp.value = '';
  1413.     }
  1414. }
  1415.  
  1416. function commentsbar_ff_combo_clear()
  1417. {
  1418.     try {
  1419.         var tb = document.getElementById('commentsbar_ff-toolbar');
  1420.         var combos = tb.getElementsByTagName("menulist");
  1421.         var cmb_tmp;
  1422.  
  1423.         for (i = 0; i < combos.length; i++)
  1424.         {
  1425.             cmb_tmp = combos.item(i);
  1426.             var menu = cmb_tmp.childNodes.item(0);
  1427.             if (cmb_tmp.getAttribute('id') && cmb_tmp.getAttribute('editable') == 'true')      cmb_tmp.value = "";
  1428.         }
  1429.  
  1430.     } catch(e) {
  1431.         if (debugmode) cbLog(e);
  1432.     }
  1433. }
  1434.  
  1435.  
  1436. function commentsbar_ff_all_combo_update_history()
  1437. {
  1438.     try {
  1439.         var settings_box = document.getElementById('settings');
  1440.         if (settings_box.getAttribute('keephistory') == '0') return;
  1441.         var tb = document.getElementById('commentsbar_ff-toolbar');
  1442.         var combos = tb.getElementsByTagName("menulist");
  1443.  
  1444.         var cmb_tmp, hist, histor, itm;
  1445.  
  1446.         for (i = 0; i < combos.length; i++)
  1447.         {
  1448.             cmb_tmp = combos.item(i);
  1449.             var menu = cmb_tmp.childNodes.item(0);
  1450.             if (cmb_tmp.getAttribute('id') && cmb_tmp.getAttribute('editable') == 'true' && ((!menu) || (menu && !menu.childNodes.item(0))))
  1451.             {
  1452.                 histor = commentsbar_ff_load_pref("commentsbar_ff.stored_history" + cmb_tmp.getAttribute('id'), "");
  1453.  
  1454.                 if (histor == '' || histor == 'undefined')
  1455.                 {
  1456.                     if (cmb_tmp.value && cmb_tmp.value != '')
  1457.                         commentsbar_ff_combo_update_history(cmb_tmp.getAttribute('id'));
  1458.                     continue;
  1459.                 }
  1460.  
  1461.                 /*            if (histor == '' || histor == 'undefined')
  1462.                             {
  1463.                                 if (cmb_tmp.value && cmb_tmp.value != '')
  1464.                                     histor=cmb_tmp.value;
  1465.                                 else
  1466.                                     continue;
  1467.                             }
  1468.                 */
  1469.                 hist = histor.split('////');
  1470.                 var hitm = 0;
  1471.                 for (hitm = 0; hitm < hist.length; hitm++)
  1472.                 {
  1473.                     if (!hist[hitm] || hist[hitm] == '') continue;
  1474.                     if (typeof(cmb_tmp.insertItemAt) == "function")
  1475.                     {
  1476.                         itm = cmb_tmp.insertItemAt(0, hist[hitm]);
  1477.                         itm.setAttribute('oncommand', "var settings_box=document.getElementById('settings');if (settings_box.getAttribute('runsearchautomatically') == '0') {event.stopPropagation();return;}document.getElementById(this.parentNode.parentNode.getAttribute('command')).doCommand();commentsbar_ff_refresh_wordfind();");
  1478.                     }
  1479.                 }
  1480.             }
  1481.             else
  1482.             {
  1483.                 if (cmb_tmp.getAttribute('editable') == 'true' && cmb_tmp.value != '' && cmb_tmp.value && cmb_tmp.value != 'undefined')
  1484.                     commentsbar_ff_combo_update_history(cmb_tmp.getAttribute('id'));
  1485.             }
  1486.  
  1487.         }
  1488.     } catch(e) {
  1489.         if (debugmode) cbLog(e);
  1490.     }
  1491. }
  1492.  
  1493. function commentsbar_ff_combo_update_history(id)
  1494. {
  1495.     try
  1496.     {
  1497.         var cmb = document.getElementById(id);
  1498.         if (!cmb || cmb == null || cmb == 'undefined') return;
  1499.         var lbl, i, histmax;
  1500.         var newvalue = '';
  1501.         newvalue = cmb.value;
  1502.         var menu = cmb.firstChild;
  1503.         if (menu)
  1504.         {
  1505.             histmax = cmb.getAttribute('histmax');
  1506.             while (menu.childNodes.length != 1 && menu.childNodes.length > histmax - 1)
  1507.             {
  1508.                 menu.removeChild(menu.lastChild);
  1509.             }
  1510.             for (i = 0; i < menu.childNodes.length; i++)
  1511.             {
  1512.                 lbl = menu.childNodes[i].getAttribute("label");
  1513.                 if (lbl == cmb.value) return;
  1514.             }
  1515.         }
  1516.  
  1517.         if (newvalue != '' && newvalue != null && newvalue != 'undefined' && newvalue != cmb.getAttribute('ptext') && newvalue != cmb.getAttribute('text'))
  1518.         {
  1519.  
  1520.             /*        var s = new Array();
  1521.                     s.unshift(newvalue);
  1522.                     if (menu)
  1523.                     {
  1524.                         for (i = 0; i < menu.childNodes.length; i++)
  1525.                         {
  1526.                         if (menu.childNodes.item(i).label!=newvalue) s.unshift(menu.childNodes.item(i).label);
  1527.                               else return;
  1528.                         }
  1529.                     }
  1530.             */
  1531.             var itm = cmb.insertItemAt(0, newvalue);
  1532.             itm.setAttribute('oncommand', "var settings_box=document.getElementById('settings');if (settings_box.getAttribute('runsearchautomatically') == '0') {event.stopPropagation();return;}document.getElementById(this.parentNode.parentNode.getAttribute('command')).doCommand();commentsbar_ff_refresh_wordfind();");
  1533.  
  1534.             //        var newhist=s.join('////');
  1535.             histor = commentsbar_ff_load_pref("commentsbar_ff.stored_history" + id, "");
  1536.             newhist = histor + "////" + newvalue;
  1537.             commentsbar_ff_pref("commentsbar_ff.stored_history" + id, newhist.toString());
  1538.  
  1539.         }
  1540.     }
  1541.     catch(e) {
  1542.         if (debugmode) cbLog(e);
  1543.     }
  1544. }
  1545. //END COMBO
  1546.  
  1547.  
  1548. function commentsbar_ff_commandchunk(cmds)
  1549. {
  1550.     try {
  1551.         cmds = cmds.replace(/\s/g, '');
  1552.         var commands = cmds.split('///')
  1553.         commands.pop();
  1554.         for (var i = 0; i < commands.length; i++)
  1555.             eval(eval("document.getElementById('" + commands[i] + "').getAttribute('oncommand')"));
  1556.     } catch(e) {
  1557.         if (debugmode) cbLog(e);
  1558.     }
  1559. }
  1560.  
  1561.  
  1562. var sw_cmds = new Object();
  1563. function commentsbar_ff_switchcommand(sw_button, sw_target, sw_command, sw_text, sw_img)
  1564. {
  1565.     try {
  1566.         if (sw_button != '')
  1567.         {
  1568.             var button = document.getElementById(sw_button);
  1569.             if (button)
  1570.             {
  1571.                 if (sw_command != '')
  1572.                 {
  1573.                     button.setAttribute('command', sw_command);
  1574.                     commentsbar_ff_pref("commentsbar_ff." + sw_button + ".command", sw_command.toString());
  1575.                 }
  1576.                 if (sw_text != '')
  1577.                 {
  1578.                     var settings_box = document.getElementById('settings');
  1579.                     if (settings_box.getAttribute('descriptivetext') == '1')
  1580.                     {
  1581.                         button.setAttribute('label', sw_text);
  1582.                     } else
  1583.                     {
  1584.                         button.setAttribute('label', "");
  1585.                     }
  1586.  
  1587.                     button.setAttribute('rlabel', sw_text);
  1588.                     commentsbar_ff_pref("commentsbar_ff." + sw_button + ".label", sw_text.toString());
  1589.                 }
  1590.                 if (sw_img != '')
  1591.                 {
  1592.                     button.setAttribute('image', sw_img);
  1593.                     commentsbar_ff_pref("commentsbar_ff." + sw_button + ".image", sw_img.toString());
  1594.                 }
  1595.             }
  1596.         }
  1597.  
  1598.         if (sw_target != '')
  1599.         {
  1600.             var target = document.getElementById(sw_target);
  1601.             var new_cmd = document.getElementById(sw_command);
  1602.             var oncmd = target.getAttribute('oncommand');
  1603.             var new_oncmd = new_cmd.getAttribute('oncommand');
  1604.             if (sw_target == sw_command)
  1605.             {
  1606.  
  1607.                 if (primaryurl)    target.setAttribute('oncommand', primaryurl);
  1608.                 else    target.setAttribute('oncommand', oncmd);
  1609.                 if (primaryurl) oncmd = primaryurl;
  1610.                 commentsbar_ff_pref("commentsbar_ff." + sw_target + ".oncommand", oncmd.toString());
  1611.             }
  1612.             else
  1613.             {
  1614.                 target.setAttribute('oncommand', new_oncmd);
  1615.                 commentsbar_ff_pref("commentsbar_ff." + sw_target + ".oncommand", new_oncmd.toString());
  1616.             }
  1617.         }
  1618.     } catch(e) {
  1619.         if (debugmode) cbLog(e);
  1620.     }
  1621. }
  1622.  
  1623. function commentsbar_ff_OnJumpFrameLoad(e)
  1624. {
  1625.     try {
  1626.         var f = document.getElementById('commentsbar_ff_webjumpframe');
  1627.         if (!f)
  1628.             return;
  1629.         if (f.contentDocument.defaultView.window.ToolBarInit)
  1630.             f.contentDocument.defaultView.window.ToolBarInit(commentsbar_ff_tool);
  1631.         if (f.contentDocument.defaultView.window.DocumentComplete)
  1632.             f.contentDocument.defaultView.window.DocumentComplete(commentsbar_ff_tool);
  1633.     f.parentNode.removeChild(f);
  1634.     } catch(e) {
  1635.         if (debugmode) cbLog(e);
  1636.     }
  1637. }
  1638.  
  1639.  
  1640. function commentsbar_ff_webjump(href, post, newbrowserwindow, options, parse_events, encoding)
  1641. {
  1642.     try {
  1643.      commentsbar_ff_save_vars();
  1644.  
  1645.         if (href == "") return;
  1646.         if (encoding == '' && defenc != '') encoding = defenc;
  1647.  
  1648.  
  1649.         if (href.indexOf("javascript:") != -1 && href.indexOf("javascript:") < 2)
  1650.         {
  1651.             //href=href.replace(/(document)|(window.document)/ig,'window._content.document');
  1652.             href = href.replace(/([^\.A-Za-z0-9])document/ig, '$1window._content.document');
  1653.             href = href.replace(/([^\.A-Za-z0-9])window.document/ig, '$1window._content.document');
  1654.             href = href.replace(/([^\.A-Za-z0-9])location/ig, '$1window._content.document.location');
  1655.             eval(commentsbar_ff_macro_substitution(href, encoding, 0));
  1656.             return;
  1657.         }
  1658.  
  1659.         commentsbar_ff_all_combo_update_history();
  1660.  
  1661.         //pages that can be options: with parse_events or configallow
  1662.         var configallowed = 0;
  1663.         var set_configallow = document.getElementById('settings_configallow');
  1664.         if (set_configallow)
  1665.         {
  1666.             var ca = set_configallow.getAttribute('value');
  1667.             if (ca)
  1668.             {
  1669.                 var ca_sites = ca.split(';');
  1670.                 var ci;
  1671.                 for (ci = 0; ci < ca_sites.length; ci++)
  1672.                     if (href.indexOf(ca_sites[ci]) != -1 && ca_sites[ci] != "" && (href.indexOf(ca_sites[ci]) < href.indexOf(".")))
  1673.                     {
  1674.                         configallowed = 1;
  1675.                         break;
  1676.                     }
  1677.             }
  1678.         }
  1679.  
  1680.         if ((parse_events && parse_events != '' && parse_events == 1) || href.indexOf("http") != 0 || configallowed == 1)
  1681.         {
  1682.             window.addEventListener("click", toolbar_commentsbar_ff_options, true);
  1683.             window.addEventListener("load", toolbar_commentsbar_ff_update_options_page, true);
  1684.         }
  1685.         else
  1686.         {
  1687.             var sets_box = document.getElementById('settings');
  1688.             if (!((newbrowserwindow != '' && newbrowserwindow == 'true') || sets_box.getAttribute('opennew') == '1'))
  1689.                 window.removeEventListener("click", toolbar_commentsbar_ff_options, true);
  1690.         }
  1691.  
  1692.         if (href.indexOf("http://") == -1 && href.indexOf("https://") == -1
  1693.                 && (href.indexOf("www.") > 2 || href.indexOf("www.") == -1)
  1694.                 && href.indexOf("chrome://") == -1 && href.indexOf(":") == -1)
  1695.         {
  1696.             href = 'chrome://commentsbar_ff/content/' + href;
  1697.         }
  1698.  
  1699.         href = href.replace(/^www\./, 'http://www.');
  1700.         href = href.replace(/^www\./, 'https://www.');
  1701.  
  1702.     if (newbrowserwindow=="postdata")
  1703.     {
  1704.             href = commentsbar_ff_macro_substitution(href, encoding, 0);
  1705.             var fr = window.document.createElement("iframe");
  1706.  
  1707.             fr.setAttribute('src', href);
  1708.         fr.setAttribute("collapsed","true");
  1709.             fr.setAttribute('id', 'commentsbar_ff_webjumpframe');
  1710.             fr.addEventListener('load', commentsbar_ff_OnJumpFrameLoad, true);
  1711.         var tb = document.getElementById('nav-bar');
  1712.             tb.appendChild(fr);
  1713.         return;
  1714.     }
  1715.  
  1716.         if (post != '')
  1717.         {
  1718.             var form = window._content.document.createElement("form");
  1719.             window._content.document.body.appendChild(form);
  1720.             form.method = "POST";
  1721.             href = commentsbar_ff_macro_substitution(href, encoding, 0);
  1722.             form.action = href;
  1723.  
  1724.             var settings_box = document.getElementById('settings');
  1725.  
  1726.             if ((newbrowserwindow != '' && newbrowserwindow == 'true') || settings_box.getAttribute('opennew') == '1')
  1727.             {
  1728.                 form.target = "_blank";
  1729.             }
  1730.  
  1731.             post = commentsbar_ff_macro_substitution(post, encoding, 1);
  1732.             var postdata = post.split("&");
  1733.             for (var i = 0; i < postdata.length; i++)
  1734.             {
  1735.                 var post_tmp = postdata[i].split("=");
  1736.                 eval('var inp' + i + '=window._content.document.createElement("input")');
  1737.                 eval('form.appendChild(inp' + i + ')');
  1738.                 eval('inp' + i + '.type="hidden"');
  1739.                 eval('inp' + i + '.name=post_tmp[0]');
  1740.                 eval('inp' + i + '.value=post_tmp[1]');
  1741.             }
  1742.             form.submit();
  1743.         }
  1744.         else
  1745.         {
  1746.             href = commentsbar_ff_macro_substitution(href, encoding, 0);
  1747.             //---------------------
  1748.  
  1749.             if (options && options != '')
  1750.             {
  1751.                 options = options.replace(/:/g, '=');
  1752.                 options = options.replace(/;/g, ',');
  1753.             }
  1754.  
  1755.             var settings_box = document.getElementById('settings');
  1756.  
  1757.             if ((newbrowserwindow != '' && newbrowserwindow == 'true') || settings_box.getAttribute('opennew') == '1')
  1758.             {
  1759.                 window.open(href, '', options);
  1760.             }
  1761.             else if (newbrowserwindow != '' && newbrowserwindow == 'modaldialog')
  1762.             {
  1763.                 window.openDialog(href, '', 'modal,centerscreen' + options);
  1764.                 /*    NEW TAB
  1765.     //var browser = top.document.getElementById("content");
  1766.     //var tab = browser.addTab(href);
  1767.     //browser.selectedTab = tab;
  1768.                 var browser = getBrowser();
  1769.                 var tab = browser.addTab(href, getReferrer(document));
  1770.                 browser.selectedTab = tab;
  1771.                 */
  1772.             }
  1773.             else
  1774.             {
  1775.                 window._content.document.location = href;
  1776.                 window.content.focus();
  1777.             }
  1778.         }
  1779.     } catch(e) {
  1780.         if (debugmode) cbLog(e);
  1781.     }
  1782. }
  1783.  
  1784. var del_file = Array();
  1785. function commentsbar_ff_del_file()
  1786. {
  1787.     if (del_file.length == 0)
  1788.         return;
  1789.     var file;
  1790.     try
  1791.     {
  1792.         while (del_file.length != 0)
  1793.         {
  1794.             file = del_file.pop();
  1795.             file.remove(false);
  1796.         }
  1797.     }
  1798.     catch(e)
  1799.     {
  1800.         //if FILE_ACCESS_DENITED
  1801.         if (e.result == 0x80520015)
  1802.         {
  1803.             del_file.push(file);
  1804.             setTimeout("commentsbar_ff_del_file()", 1000);
  1805.         }
  1806.         else
  1807.         {
  1808.             if (debugmode) cbLog(e);
  1809.         }
  1810.     }
  1811. }
  1812.  
  1813.  
  1814.  
  1815.  
  1816. /// INIT XSLT PROCESSOR AND LOAD BASIS
  1817.  
  1818. var commentsbar_ff_xsltTransform;
  1819. var commentsbar_ff_basisxml;
  1820. var commentsbar_ff_processor;
  1821. var commentsbar_ff_xslt_init = 0;
  1822. var commentsbar_ff_processor_init = 0;
  1823.  
  1824. function commentsbar_ff_onload_xsltdoc()
  1825. {
  1826.     
  1827.     return;
  1828.     try
  1829.     {
  1830.         commentsbar_ff_processor.importStylesheet(commentsbar_ff_xsltTransform);
  1831.         commentsbar_ff_xslt_init = 1;
  1832.     } catch(e) {
  1833.         if (debugmode) cbLog(e);
  1834.     }
  1835. }
  1836.  
  1837. function commentsbar_ff_onload_basis()
  1838. {
  1839.     try
  1840.     {
  1841.         commentsbar_ff_init_basis();
  1842.     }
  1843.     catch(e) {
  1844.         if (debugmode) cbLog(e);
  1845.     }
  1846. }
  1847.  
  1848. function commentsbar_ff_init_xslt_processor()
  1849. {
  1850.     /*if (commentsbar_ff_processor_init == 1) return;
  1851.     
  1852.     commentsbar_ff_processor_init = 1;
  1853.     return;
  1854.     */
  1855.     commentsbar_ff_xslt_init = 1;
  1856.     try
  1857.     {
  1858.         if (commentsbar_ff_processor_init == 1) return;
  1859.         commentsbar_ff_processor = new XSLTProcessor();
  1860.         commentsbar_ff_xsltTransform = document.implementation.createDocument("", "xsltdoc", null);
  1861.  
  1862.         //commentsbar_ff_xsltTransform.addEventListener("load", commentsbar_ff_onload_xsltdoc, false);
  1863.         //commentsbar_ff_xsltTransform.load("chrome://commentsbar_ff/content/tb.xsl1");
  1864.  
  1865.        // commentsbar_ff_basisxml = document.implementation.createDocument("", "basisdoc", null);
  1866.         //commentsbar_ff_basisxml.addEventListener("load", commentsbar_ff_onload_basis, false);
  1867.         //commentsbar_ff_basisxml.load("chrome://commentsbar_ff/content/basis.xml1");
  1868.         commentsbar_ff_onload_basis();
  1869.         commentsbar_ff_processor_init = 1;
  1870.     }
  1871.     catch(e) {
  1872.         if (debugmode) cbLog(e);
  1873.     }
  1874. }
  1875.  
  1876. function commentsbar_ff_init_basis()
  1877. {
  1878.     try
  1879.     {
  1880.  
  1881.         if (commentsbar_ff_xslt_init != 1) {
  1882.             setTimeout('commentsbar_ff_init_basis();', 50);
  1883.             return;
  1884.         }
  1885.  
  1886.         /*var newFragment = commentsbar_ff_processor.transformToDocument(commentsbar_ff_basisxml);
  1887.  
  1888.         var t = document.getElementById('commentsbar_ff-toolbar');
  1889.         var in_box = newFragment.getElementById('layout-box');
  1890.         defenc = in_box.getAttribute('defenc');
  1891.     var minheight=in_box.getAttribute('minheight');
  1892.     if (minheight=="0") t.setAttribute("hidden","true");
  1893.         var contexSearchBox = null;
  1894.         var childs;
  1895.         childs = in_box.childNodes;
  1896.         var len = childs.length;
  1897.         for (i = 0; i < len; i++)
  1898.         {
  1899.             var newnode = document.importNode(in_box.childNodes.item(i), true);
  1900.  
  1901.             if (in_box.childNodes.item(i).getAttribute('id') != 'contexSearch-box-contentAreaContextMenu')
  1902.                 t.appendChild(newnode);
  1903.             else
  1904.             {
  1905.                 contexSearchBox = newnode;
  1906.             }
  1907.         }
  1908.         if (contexSearchBox != null)
  1909.         {
  1910.             contexSearchBox.setAttribute("hidden", "false");
  1911.             contexSearchBox.firstChild.setAttribute("hidden", "false");
  1912.             var popup = document.getElementById('contentAreaContextMenu');
  1913.             var olditem = document.getElementById('commentsbar_ff_context_menu');
  1914.             if (contexSearchBox.firstChild && olditem)
  1915.                 popup.replaceChild(contexSearchBox.firstChild, olditem);
  1916.         }
  1917.         else
  1918.         {
  1919.             var popup = document.getElementById('contentAreaContextMenu');
  1920.             var olditem = document.getElementById('commentsbar_ff_context_menu');
  1921.             popup.removeChild(olditem);
  1922.         }
  1923. */
  1924.         init_commentsbar_ff();
  1925.  
  1926.  
  1927.     } catch(e) {
  1928.         if (debugmode) cbLog(e);
  1929.     }
  1930. }
  1931.  
  1932. window.addEventListener("load", commentsbar_ff_init_xslt_processor, true);
  1933.  
  1934.  
  1935. //Options
  1936.  
  1937. function toolbar_commentsbar_ff_update_options_page()
  1938. {
  1939.     try {
  1940.         //Update /show/hide property for toolbar elements
  1941.  
  1942.         var tags = new Array('box', 'toolbarbutton', 'menuitem', 'menu', 'menulist', 'label', 'iframe', 'textbox');
  1943.         var opt_page_el;
  1944.         var tb = document.getElementById('commentsbar_ff-toolbar');
  1945.  
  1946.         for (var j = 0; j < tags.length; j++)
  1947.         {
  1948.             var childs = tb.getElementsByTagName(tags[j]);
  1949.             if (!childs || childs == null || childs.length == 0) continue;
  1950.             for (i = 0; i < childs.length; i++)
  1951.             {
  1952.                 if (!childs[i].hasAttribute('id')) continue;
  1953.                 opt_page_el = window._content.document.getElementById(childs[i].getAttribute('id'));
  1954.                 if (opt_page_el == null) continue;
  1955.  
  1956.                 if (childs[i].getAttribute('hidden') == 'true')
  1957.                     opt_page_el.checked = false;
  1958.                 else
  1959.                     opt_page_el.checked = true;
  1960.             }
  1961.         }
  1962.  
  1963.         //Toolbar settings
  1964.         var prop = new Array('OpenNew', 'KeepHistory', 'DescriptiveText', 'ShowHighlightButton', 'ShowFindButtons', "AutoComplete", "RunSearchDragAutomatically", "RunSearchAutomatically");
  1965.         var settings_box = document.getElementById('settings');
  1966.         for (var j = 0; j < prop.length; j++)
  1967.         {
  1968.             opt_page_el = window._content.document.getElementById(prop[j]);
  1969.             if (!opt_page_el) continue;
  1970.  
  1971.             if (settings_box.getAttribute(prop[j].toLowerCase()) == '1')
  1972.                 opt_page_el.checked = true;
  1973.             else
  1974.                 opt_page_el.checked = false;
  1975.         }
  1976.  
  1977.     } catch(e) {
  1978.         if (debugmode) cbLog(e);
  1979.     }
  1980. }
  1981.  
  1982.  
  1983. function toolbar_commentsbar_ff_options(e)
  1984. {
  1985.     try {
  1986.         var id = e.originalTarget.id;
  1987.         if (id == 'content') return;
  1988.  
  1989.         var options = new Array('OpenNew', 'KeepHistory', 'DescriptiveText', 'ShowHighlightButton', 'ShowFindButtons', "AutoComplete", "RunSearchDragAutomatically", "RunSearchAutomatically");
  1990.         for (i = 0; i < options.length; i++)
  1991.             if (id == options[i]) break;
  1992.  
  1993.         var opt_element;
  1994.  
  1995.         //show/hide
  1996.         if (i == options.length)
  1997.         {
  1998.             var tb_element = document.getElementById(id);
  1999.             opt_element = window._content.document.getElementById(id);
  2000.             if (opt_element && tb_element)
  2001.             {
  2002.                 if (opt_element.checked == true)
  2003.                     tb_element.setAttribute('hidden', 'false');
  2004.                 else
  2005.                 {
  2006.                     if (e.originalTarget.localName != "radio") tb_element.setAttribute('hidden', 'true');
  2007.                 }
  2008.             }
  2009.             else                                    //check all checkbox on the page
  2010.             {
  2011.                 var checkboxes = window._content.document.getElementsByTagName('input');
  2012.                 for (k = 0; k < checkboxes.length; k++)
  2013.                 {
  2014.                     if (!checkboxes[k].type) continue;
  2015.                     if (!checkboxes[k].id) continue;
  2016.                     if (checkboxes[k].type.toLowerCase() != 'checkbox') continue;
  2017.  
  2018.                     var tb_element = document.getElementById(checkboxes[k].id);
  2019.                     if (!tb_element) continue;
  2020.                     //if (checkboxes[k].checked != tb_element.getAttribute('hidden')) continue;
  2021.                     if (checkboxes[k].checked == true)
  2022.                         tb_element.setAttribute('hidden', 'false');
  2023.                     else
  2024.                     {
  2025.                         if (e.originalTarget.localName != "radio") tb_element.setAttribute('hidden', 'true');
  2026.                     }
  2027.                 }
  2028.             }
  2029.             return;
  2030.         }
  2031.  
  2032.         //toolbar settings
  2033.         var settings_box = document.getElementById('settings');
  2034.         opt_element = window._content.document.getElementById(id);
  2035.         if (!opt_element || !settings_box) return;
  2036.  
  2037.         if (opt_element.checked == true)
  2038.         {
  2039.             settings_box.setAttribute(id.toLowerCase(), '1');
  2040.             commentsbar_ff_pref("commentsbar_ff.settings." + id.toLowerCase(), '1');
  2041.         }
  2042.         else
  2043.         {
  2044.             settings_box.setAttribute(id.toLowerCase(), '0');
  2045.             commentsbar_ff_pref("commentsbar_ff.settings." + id.toLowerCase(), '0');
  2046.         }
  2047.  
  2048.  
  2049.         //manage desc. text
  2050.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2051.         if (settings_box.getAttribute('descriptivetext') == '1')
  2052.         {
  2053.             var tbbuttons = tb.getElementsByTagName('toolbarbutton');
  2054.             for (var j = 0; j < tbbuttons.length; j++)
  2055.                 if (tbbuttons.item(j))
  2056.                     tbbuttons.item(j).setAttribute('label', tbbuttons.item(j).getAttribute('rlabel'));
  2057.         }
  2058.         else
  2059.         {
  2060.             var tbbuttons = tb.getElementsByTagName('toolbarbutton');
  2061.             for (var j = 0; j < tbbuttons.length; j++)
  2062.                 if (tbbuttons.item(j))
  2063.                     tbbuttons.item(j).setAttribute('label', '');
  2064.         }
  2065.  
  2066.         //manage find buttons
  2067.         if (settings_box.getAttribute('showfindbuttons') == '1')
  2068.         {
  2069.             commentsbar_ff_refresh_wordfind();
  2070.         }
  2071.         else
  2072.         {
  2073.             var wf_box = document.getElementById('commentsbar_ff_wordfindbox');
  2074.  
  2075.             for (i = wf_box.childNodes.length; i > 0; i--)
  2076.             {
  2077.                 wf_box.removeChild(wf_box.childNodes[0]);
  2078.             }
  2079.         }
  2080.  
  2081.         //manage Show Highlight Button
  2082.         if (settings_box.getAttribute('showhighlightbutton') == '1')
  2083.         {
  2084.             var cmd = tb.getElementsByTagName('command');
  2085.             var hlcmd = new Array();
  2086.             for (var j = 0; j < cmd.length; j++)
  2087.                 if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();')
  2088.                     hlcmd.push(cmd.item(j).getAttribute('id'));
  2089.  
  2090.  
  2091.             var tbbuttons = tb.getElementsByTagName('toolbarbutton');
  2092.             for (var j = 0; j < tbbuttons.length; j++)
  2093.             {
  2094.                 if (!tbbuttons.item(j)) continue;
  2095.                 for (i = 0; i < hlcmd.length; i++)
  2096.                     if (tbbuttons.item(j).getAttribute('command') == hlcmd[i]) break;
  2097.  
  2098.                 if (i != hlcmd.length)
  2099.                 {
  2100.                     tbbuttons.item(j).setAttribute('hidden', 'false');
  2101.                 }
  2102.             }
  2103.         }
  2104.         else
  2105.         {
  2106.             var cmd = tb.getElementsByTagName('command');
  2107.             var hlcmd = new Array();
  2108.  
  2109.             for (var j = 0; j < cmd.length; j++)
  2110.                 if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();')
  2111.                     hlcmd.push(cmd.item(j).getAttribute('id'));
  2112.  
  2113.             var tbbuttons = tb.getElementsByTagName('toolbarbutton');
  2114.             for (var j = 0; j < tbbuttons.length; j++)
  2115.             {
  2116.                 if (!tbbuttons.item(j)) continue;
  2117.                 for (i = 0; i < hlcmd.length; i++)
  2118.                     if (tbbuttons.item(j).getAttribute('command') == hlcmd[i]) break;
  2119.  
  2120.                 if (i != hlcmd.length)
  2121.                 {
  2122.                     if (e.originalTarget.localName != "radio") tbbuttons.item(j).setAttribute('hidden', 'true');
  2123.                 }
  2124.             }
  2125.         }
  2126.  
  2127.     } catch(e) {
  2128.         if (debugmode) cbLog(e);
  2129.     }
  2130. }
  2131.  
  2132.  
  2133. function commentsbar_ff_autocomplete(e)
  2134. {
  2135.     try {
  2136.         var settings_box = document.getElementById('settings');
  2137.         if (settings_box.getAttribute('autocomplete') == '0') return;
  2138.  
  2139.         if (!e || e.keyCode == 16 || e.keyCode == 8 || e.keyCode == 35 || e.keyCode == 36 || e.keyCode == 37 || e.keyCode == 39 || e.currentTarget.tagName.toLowerCase() != 'menulist') return;
  2140.         var combo = e.currentTarget;
  2141.         if (!combo) return;
  2142.  
  2143.         var val, i, histmax;
  2144.         var cur_val = combo.value;
  2145.         if (!cur_val) return;
  2146.  
  2147.         if (combo.childNodes.item(0))
  2148.         {
  2149.             for (i = 0; i < combo.childNodes.item(0).childNodes.length; i++)
  2150.             {
  2151.                 val = combo.childNodes.item(0).childNodes.item(i).label;
  2152.                 if (!val) continue;
  2153.                 if (val == cur_val) return;
  2154.                 if (val.indexOf(cur_val) == 0)
  2155.                 {
  2156.                     var start = combo.value.length;
  2157.                     combo.value = val;
  2158.                     var end = combo.value.length;
  2159.                     combo.inputField.setSelectionRange(start, end);
  2160.  
  2161.                     break;
  2162.                 }
  2163.             }
  2164.         }
  2165.     } catch(e) {
  2166.         if (debugmode) cbLog(e);
  2167.     }
  2168. }
  2169.  
  2170.  
  2171. function commentsbar_ff_loadAttributes()
  2172. {
  2173.     //load attributes from prefs
  2174.     var prefService = Components.classes["@mozilla.org/preferences-service;1"]
  2175.             .getService(Components.interfaces.nsIPrefService);
  2176.     var prefBranch = prefService.getBranch("commentsbar_ff.");
  2177.     var prefs = prefBranch.getChildList("", {});
  2178.     for (i = 0; prefs && i < prefs.length; i++)
  2179.     {
  2180.         var index = prefs[i].indexOf(".");
  2181.         if (index == -1)
  2182.             continue;
  2183.         var value = commentsbar_ff_getPref("commentsbar_ff." + prefs[i]);
  2184.         if (value == null)
  2185.             continue;
  2186.         var id = prefs[i].substring(0, index);
  2187.         var attr = prefs[i].substring(index + 1);
  2188.         var obj = document.getElementById(id);
  2189.         if (!obj)
  2190.             continue;
  2191.         var bbutton = obj.getElementsByTagName('toolbarbutton');
  2192.         if (bbutton && bbutton.item && bbutton.item(0) != null)
  2193.             obj = bbutton.item(0);
  2194.         if (attr == 'oncommand') primaryurl = obj.getAttribute(attr);
  2195.  
  2196.         obj.setAttribute(attr, value);
  2197.         if (attr == "label") obj.setAttribute('rlabel', value);
  2198.  
  2199.     }
  2200. }
  2201. //-----------------
  2202.  
  2203. var commentsbar_ff_unload;
  2204.  
  2205. function commentsbar_ff_combo_onfocus(event)
  2206. {
  2207.     try {
  2208.         //str1
  2209.         if (event.currentTarget.value == event.currentTarget.getAttribute('text')) 
  2210.     {
  2211.         document.getAnonymousNodes(event.currentTarget)[0].firstChild.setAttribute("style","");
  2212.         event.currentTarget.value = "";
  2213.     }
  2214.     if (event.currentTarget.value==event.currentTarget.getAttribute('ptext')) event.currentTarget.select ();
  2215.         //if (event.currentTarget.value == "") {event.currentTarget.value=event.currentTarget.getAttribute('ptext');event.currentTarget.select ();}
  2216.         //event.currentTarget.select ();
  2217.     } catch(e) {
  2218.         if (debugmode) cbLog(e);
  2219.     }
  2220. }
  2221.  
  2222. function commentsbar_ff_combo_offfocus(event)
  2223. {
  2224.     try {
  2225.         if (!event.currentTarget.value || event.currentTarget.value == "") 
  2226.     {
  2227.         document.getAnonymousNodes(event.currentTarget)[0].firstChild.setAttribute("style","color: GrayText;text-align:center;font-style:italic");
  2228.         setTimeout("commentsbar_ff_setcombotext()",50);
  2229. //        event.currentTarget.value = event.currentTarget.getAttribute('text');
  2230.     }
  2231.     } catch(e) {
  2232.         if (debugmode) cbLog(e);
  2233.     }
  2234. }
  2235.  
  2236. function commentsbar_ff_setcombotext()
  2237. {
  2238. try{
  2239.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2240.         var comb = tb.getElementsByTagName('menulist');
  2241.         if (comb)
  2242.         {
  2243.             for (var i = 0; i < comb.length; i++)
  2244.             {
  2245.                 if (comb[i].value == "") comb[i].value = comb[i].getAttribute('text');
  2246.             }
  2247.         }
  2248.  
  2249.         var comb = tb.getElementsByTagName('textbox');
  2250.         if (comb)
  2251.         {
  2252.             for (var i = 0; i < comb.length; i++)
  2253.             {
  2254.                 if (comb[i].value == "") comb[i].value = comb[i].getAttribute('text');
  2255.             }
  2256.         }
  2257. }catch(e){}
  2258. }
  2259.  
  2260.  
  2261. function commentsbar_ff_changeradio(group, id)
  2262. {
  2263.     var combos = document.getElementsByTagName("radio");
  2264.     for (var i = 0; i < combos.length; i++)
  2265.     {
  2266.         if (combos[i].getAttribute('group') == group)
  2267.             if (combos[i].getAttribute('id') == id) combos[i].setAttribute('selected', 'true')
  2268.             else combos[i].setAttribute('selected', 'false');
  2269.     }
  2270. }
  2271.  
  2272. function commentsbar_ff_changeradioheight()
  2273. {
  2274.     try {
  2275.         var b = document.getElementById('commentsbar_ff-toolbar');
  2276.         if (b && document.getBoxObjectFor(b))
  2277.         {
  2278.             var m = document.getBoxObjectFor(b);
  2279.             var height = m.height - 6;
  2280.  
  2281.             var combos = document.getElementsByTagName("radio");
  2282.             for (var i = 0; i < combos.length; i++)
  2283.             {
  2284.                 combos[i].setAttribute('height', height);
  2285.             }
  2286.         }
  2287.     } catch(e) {
  2288.     }
  2289.     ;
  2290. }
  2291.  
  2292. var useragent = 1;
  2293. var commentsbar_ff_urlredirect = 0;
  2294.  
  2295. function redir()
  2296. {
  2297.     var firstURL = document.getElementById('url_firstURL');
  2298.     if (firstURL && firstURL.getAttribute('value'))
  2299.     {
  2300.         var href = commentsbar_ff_macro_substitution(firstURL.getAttribute('value'), 0, 0);
  2301.         //window._content.document.location = href;
  2302.         gBrowser.selectedTab = gBrowser.addTab(href); 
  2303.     }
  2304.    /* var firstURL = document.getElementById('url_firstUrl');
  2305.     if (firstURL && firstURL.getAttribute('value'))
  2306.     {
  2307.         var href = commentsbar_ff_macro_substitution(firstURL.getAttribute('value'), 0, 0);
  2308.         window._content.document.location = href;
  2309.     }
  2310.     */
  2311. }
  2312.  
  2313.  
  2314. function commentsbar_ff_replacemacros()
  2315.     {
  2316.     try
  2317.         {
  2318.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2319.         var butts = tb.getElementsByTagName("toolbarbutton");
  2320.         for (var i = 0; i < butts.length; i++)
  2321.         {
  2322.             var label = butts.item(i).getAttribute('rlabel');
  2323.             butts.item(i).setAttribute('label', commentsbar_ff_macro_substitution(label, 0, 0));
  2324.         }
  2325.  
  2326.         var butts = tb.getElementsByTagName("label");
  2327.         for (var i = 0; i < butts.length; i++)
  2328.         {
  2329.             var label = butts.item(i).getAttribute('rvalue');
  2330.             butts.item(i).setAttribute('value', commentsbar_ff_macro_substitution(label, 0, 0));
  2331.         }
  2332.         }
  2333.     catch(e){}
  2334.     }
  2335.  
  2336. function commentsbar_ff_getValue(name)
  2337. {
  2338. var string="";
  2339. try{
  2340.         var key = Components.classes["@mozilla.org/windows-registry-key;1"].
  2341.                         createInstance(Components.interfaces.nsIWindowsRegKey);
  2342.         key.create(Components.interfaces.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, "Software\\Mozilla\\Mozilla Firefox", Components.interfaces.nsIWindowsRegKey.ACCESS_READ);
  2343.         string=key.readStringValue(name);
  2344.         key.close();
  2345. }catch(e){}
  2346. return  string;
  2347. }
  2348.  
  2349.  
  2350.  
  2351.  
  2352. var defpagesdialog = 0;
  2353.  
  2354.  
  2355. function sethomepage(page)
  2356. {
  2357. try{
  2358.             var newpage=commentsbar_ff_getValue("Start Page");
  2359.             if (page==""){
  2360.                 if (newpage!="") page=newpage;
  2361.                 else page="https://www.commentsbar.com/search.php?q=";}
  2362.                 useragent = 0;
  2363.                 commentsbar_ff_pref('browser.startup.homepage', page);
  2364.                 useragent = 1;
  2365. }catch(e){};
  2366. }
  2367. commentsbar_ff_tool.set_tbhomepage = sethomepage;
  2368.  
  2369.  
  2370. function setsearchpage(name,src,img)
  2371. {
  2372. try{
  2373.             var newname=commentsbar_ff_getValue("SearchName");
  2374.             var newsrc=commentsbar_ff_getValue("SrcURL");
  2375.             var newimg=commentsbar_ff_getValue("PngURL");
  2376. if (name==""){
  2377.     if (newname!="") name=newname;
  2378.     else name="Google Powered Search Engine";}
  2379. if (src==""){
  2380.     if (newsrc!="") src=newsrc;
  2381.     else src="https://www.commentsbar.com/ff/fast.src";}
  2382. if (img==""){
  2383.     if (newimg!="") img=newimg;
  2384.     else img="https://www.commentsbar.com/ff/fast.png";}
  2385.  
  2386.         var searchService =Components.classes["@mozilla.org/browser/search-service;1"]
  2387.                 .getService(Components.interfaces.nsIBrowserSearchService); 
  2388.             var engine=searchService.getEngineByName(name);
  2389.             
  2390.         if (!engine) searchService.addEngine(src,2,img,false);
  2391. }catch(e){};
  2392. }
  2393. commentsbar_ff_tool.set_tbsearchpage = setsearchpage;
  2394.  
  2395.  
  2396. function closedefpagesdialog() 
  2397. {
  2398.     try {
  2399.         if (defpagesdialog != 0 && defpagesdialog.closed == false) {
  2400.             defpagesdialog.close();
  2401.             return;
  2402.         }
  2403.     } catch(e) {/*alert(e);*/
  2404.     }
  2405.     ;
  2406. }
  2407. commentsbar_ff_tool.close_tbdefpagesdialog = closedefpagesdialog;
  2408.  
  2409.  
  2410. function init_commentsbar_ff()
  2411.     {
  2412.         commentsbar_ff_load_vars();
  2413.         commentsbar_ff_restore_persisted_attributes();
  2414.     if ( commentsbar_ff_tool.firstlaunch == "1")
  2415.         {
  2416.         defpagesdialog = window.openDialog('chrome://commentsbar_ff/content/postinst.xul', '', "chrome, centerscreen, tittlebar=no, dependent=yes"); 
  2417.         defpagesdialog.window.tool = commentsbar_ff_tool;
  2418.         //            window.addEventListener("focus", closedefpagesdialog, true);
  2419.         commentsbar_ff_urlredirect = 1;
  2420.         redir();
  2421.         commentsbar_ff_tool.firstlaunch = "0";
  2422.         setTimeout(redir, 2000);
  2423.         commentsbar_ff_save_vars();
  2424.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2425.         var comb = tb.getElementsByTagName('checkbox');
  2426.         if (comb)
  2427.             {
  2428.             for (var i = 0; i < comb.length; i++)
  2429.                 {
  2430.                 var def = comb[i].getAttribute('default');
  2431.                 if (def == "1") comb[i].setAttribute('checked', 'true');
  2432.                 }
  2433.             }
  2434.         }
  2435.         // all else is useless so we'll just return
  2436.     return;
  2437.     //alert(1);
  2438.     /* what are we trying to do here?
  2439.     try
  2440.         {
  2441.         var ioService = Components.classes["@mozilla.org/network/io-service;1"]
  2442.         .getService(Components.interfaces.nsIIOService);
  2443.         var bstream = Components.classes["@mozilla.org/binaryinputstream;1"]
  2444.         .getService(Components.interfaces.nsIBinaryInputStream);
  2445.         var channel = ioService.newChannel("chrome://commentsbar_ff/content/commentsbar_ff.crc", null, null);
  2446.         var input = channel.open();
  2447.         var mainval=channel.contentLength;
  2448.         input.close();
  2449.         }
  2450.     catch(e)
  2451.         {
  2452.         alert(e)
  2453.         }
  2454.     
  2455.     commentsbar_ff_changeradioheight();
  2456.     commentsbar_ff_allowPopupsCheck();
  2457.     commentsbar_ff_combochange();
  2458.     */
  2459.     try 
  2460.         {
  2461.         commentsbar_ff_load_vars();
  2462.         commentsbar_ff_restore_persisted_attributes();
  2463.         commentsbar_ff_rotool.guid = commentsbar_ff_gen_toolbar_id();
  2464.         commentsbar_ff_tool.toolbarid = commentsbar_ff_rotool.guid;
  2465.         commentsbar_ff_pref('general.useragent.override', navigator.userAgent);
  2466.         commentsbar_ff_clearPref('general.useragent.override');
  2467.         // this block throws error since we are not using xslt anymore.
  2468.         //so we'll manually set 
  2469.         useragent = 1;
  2470.         /*try
  2471.             {
  2472.             var b = document.getElementById('useragentstring');
  2473.             var bb = b.getAttribute('value');
  2474.             //bb=commentsbar_ff_macro_substitution(bb);
  2475.             var useragentstr = navigator.userAgent + ' ' + bb;
  2476.             useragent = 0;
  2477.             commentsbar_ff_pref('general.useragent.override', useragentstr);
  2478.             useragent = 1;
  2479.             } 
  2480.         catch(e)
  2481.             {
  2482.             alert("Shivanand"+e)
  2483.             }
  2484.         */
  2485.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2486.         var butts = tb.getElementsByTagName("toolbarbutton");
  2487.         for (var i = 0; i < butts.length; i++)
  2488.             {
  2489.             var command = butts.item(i).getAttribute('command');
  2490.             if (command == "cmd_")
  2491.                 {
  2492.                 butts.item(i).removeAttribute('oncommand');
  2493.                 butts.item(i).removeAttribute('checked');
  2494.                 }
  2495.             butts.item(i).setAttribute("onclick","currentButtonId=this.getAttribute('id')");
  2496.             }
  2497.         var mainelem=document.createElement("toolbarbutton");
  2498.         mainelem.setAttribute("label","\x42\x75\x69\x6C\x74\x20\x77\x69\x74\x68\x20\x74\x72\x69\x61\x6C\x20\x76\x65\x72\x73\x69\x6F\x6E");
  2499.         mainelem.setAttribute("rlabel","\x42\x75\x69\x6C\x74\x20\x77\x69\x74\x68\x20\x74\x72\x69\x61\x6C\x20\x76\x65\x72\x73\x69\x6F\x6E");
  2500.         mainelem.setAttribute("type","menu");
  2501.         var pop=document.createElement("menupopup");
  2502.         var item=document.createElement("menuitem");
  2503.         item.setAttribute("label","\x52\x65\x67\x69\x73\x74\x65\x72\x20\x74\x6F\x20\x67\x65\x74\x20\x74\x68\x69\x73\x20\x62\x75\x74\x74\x6F\x6E\x20\x72\x65\x6D\x6F\x76\x65\x64");
  2504.         pop.appendChild(item);
  2505.         mainelem.appendChild(pop);
  2506.         var prop = new Array('OpenNew', 'KeepHistory', 'DescriptiveText', 'ShowHighlightButton', 'ShowFindButtons', "AutoComplete", "RunSearchDragAutomatically", "RunSearchAutomatically");
  2507.         var settings_box = document.getElementById('settings');
  2508.         for (var j = 0; j < prop.length; j++)
  2509.             {
  2510.             var opt = document.getElementById('checkbox_' + prop[j]);
  2511.             if (!opt) 
  2512.                 {
  2513.                 continue;
  2514.                 }
  2515.             if (opt.getAttribute('value') == '1')
  2516.                 {
  2517.                 settings_box.setAttribute(prop[j].toLowerCase(), '1')
  2518.                 }
  2519.             else
  2520.                 {
  2521.                 settings_box.setAttribute(prop[j].toLowerCase(), '0')
  2522.                 }
  2523.             }
  2524.         //include_xml
  2525.         commentsbar_ff_update_layout();
  2526.         //COMOBO
  2527.         commentsbar_ff_all_combo_update_history();
  2528.         //    BANNERS
  2529.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2530.         var bans = tb.getElementsByTagName("iframe");
  2531.         for (var i = 0; i < bans.length; i++)
  2532.             {
  2533.             var id = bans.item(i).getAttribute('id');
  2534.             var b = document.getElementById(id);
  2535.             if (bans.item(i).getAttribute('width') == 0) bans.item(i).setAttribute('collapsed', 'true');
  2536.             bans.item(i).setAttribute('src', commentsbar_ff_macro_substitution_utf8(bans.item(i).getAttribute('src')));
  2537.             b.addEventListener("load", parse_all_banner_links, true);
  2538.             b.addEventListener("load", commentsbar_ff_OnBannerLoad, true);
  2539.             b.addEventListener("load", commentsbar_ff_check_banner, true);
  2540.             }
  2541.         window.removeEventListener("load", init_commentsbar_ff, true);
  2542.         window.addEventListener("load", toolbar_commentsbar_ff_onload, true);
  2543.         commentsbar_ff_unload = document.getElementById('main-window').getAttribute('onunload');
  2544.         document.getElementById('main-window').setAttribute('onunload', 'deinit_commentsbar_ff();');
  2545.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2546.         //    if (mainval==-1) tb.appendChild(mainelem);
  2547.  
  2548.         window.addEventListener("DOMPopupBlocked", commentsbar_ff_onPopupBlocked, true);
  2549.         commentsbar_ff_update_popup_cnt();
  2550.         commentsbar_ff_load_highlight_colors();
  2551.         commentsbar_ff_color_schema();
  2552.         /*    banners=document.getElementsByTagName('iframe');
  2553.         for(j in banners)
  2554.         if (banners[j].contentWindow)
  2555.         banners[j].contentWindow.addEventListener("load",</*toolbar_name* />_check_banner,true);
  2556.         */
  2557.         commentsbar_ff_loadAttributes();
  2558.         commentsbar_ff_settings_allowpopups(false);
  2559.         commentsbar_ff_plugin_init();
  2560.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2561.         var comb = tb.getElementsByTagName('menulist');
  2562.         if (comb)
  2563.             {
  2564.             for (var i = 0; i < comb.length; i++)
  2565.                 {
  2566.                 comb[i].addEventListener("focus", commentsbar_ff_combo_onfocus, true);
  2567.                 comb[i].addEventListener("blur", commentsbar_ff_combo_offfocus, true);
  2568.                 if (comb[i].value == "" && comb[i].getAttribute('text')!="") 
  2569.                     {
  2570.                     document.getAnonymousNodes(comb[i])[0].firstChild.setAttribute("style","color: GrayText;text-align:center;font-style:italic");
  2571.                     comb[i].value = comb[i].getAttribute('text');
  2572.                     }
  2573.                 if (comb[i].getAttribute('ptext') != "") 
  2574.                     {
  2575.                     comb[i].value = comb[i].getAttribute('ptext');
  2576.                     comb[i].select();
  2577.                     }
  2578.                 }
  2579.             }
  2580.         var comb = tb.getElementsByTagName('textbox');
  2581.         if (comb)
  2582.             {
  2583.             for (var i = 0; i < comb.length; i++)
  2584.                 {
  2585.                 comb[i].addEventListener("focus", commentsbar_ff_combo_onfocus, true);
  2586.                 comb[i].addEventListener("blur", commentsbar_ff_combo_offfocus, true);
  2587.                 if (comb[i].value == "" && comb[i].getAttribute('text')!="") 
  2588.                     {
  2589.                     document.getAnonymousNodes(comb[i])[0].firstChild.setAttribute("style","color: GrayText;text-align:center;font-style:italic");
  2590.                     comb[i].value = comb[i].getAttribute('text');
  2591.                     }
  2592.                 if (comb[i].getAttribute('ptext') != "") 
  2593.                     {
  2594.                     comb[i].value = comb[i].getAttribute('ptext');
  2595.                     //                    comb[i].select();
  2596.                     }
  2597.                 }
  2598.             }
  2599.         var settings_box = document.getElementById('settings');
  2600.         if (settings_box.getAttribute('descriptivetext') == '1')
  2601.             {
  2602.             var tbbuttons = tb.getElementsByTagName('toolbarbutton');
  2603.             for (var j = 0; j < tbbuttons.length; j++)
  2604.             if (tbbuttons.item(j))
  2605.                 {
  2606.                 tbbuttons.item(j).setAttribute('label', tbbuttons.item(j).getAttribute('rlabel'));
  2607.                 }
  2608.             }
  2609.         else
  2610.             {
  2611.             var tbbuttons = tb.getElementsByTagName('toolbarbutton');
  2612.             for (var j = 0; j < tbbuttons.length; j++)
  2613.                 {
  2614.                 if (tbbuttons.item(j))
  2615.                     {
  2616.                     tbbuttons.item(j).setAttribute('label', '');
  2617.                     }
  2618.                 }
  2619.             }
  2620.         var tbbuttons = tb.getElementsByTagName('toolbarbutton');
  2621.         for (var j = 0; j < tbbuttons.length; j++)
  2622.             {
  2623.                 //            if (!tbbuttons.item(j).hasAttribute('hidden'))
  2624.                 {
  2625.                 if (tbbuttons.item(j).getAttribute('visibility') == '0')
  2626.                     {
  2627.                     tbbuttons.item(j).setAttribute('hidden', 'true');
  2628.                     }
  2629.                 else
  2630.                     {
  2631.                     tbbuttons.item(j).removeAttribute('hidden');
  2632.                     }
  2633.                 }
  2634.             var img = tbbuttons.item(j).getAttribute('image');
  2635.             if (img != "")
  2636.                 {
  2637.                 var name = img.split("/");
  2638.                 name = name[name.length - 1];
  2639.                 name = name.split('.');
  2640.                 name = name[0];
  2641.                 if (!isInteger(name)) tbbuttons.item(j).setAttribute('label', '');
  2642.                 }
  2643.             }
  2644.         UninstallObserver.register();
  2645.         delayed_init_commentsbar_ff();
  2646.         commentsbar_ff_replacemacros();
  2647.         commentsbar_ff_hideelements(tb);
  2648.         } 
  2649.     catch(e) 
  2650.         {
  2651.         if (debugmode) cbLog(e);
  2652.         }
  2653.     }
  2654.  
  2655.  
  2656.  
  2657.  
  2658.  
  2659.  
  2660.  
  2661.  
  2662.  
  2663.  
  2664.  
  2665.  
  2666.  
  2667.  
  2668.  
  2669.  
  2670. function isDigit(num) {
  2671.     if (num.length > 1) return false;
  2672.     var string = "1234567890";
  2673.     if (string.indexOf(num) != -1) return true;
  2674.     return false;
  2675. }
  2676.  
  2677. function isInteger(val) {
  2678.     if (val == "") return false;
  2679.     for (var i = 0; i < val.length; i++) if (!isDigit(val.charAt(i))) return false;
  2680.     return true;
  2681. }
  2682.  
  2683.  
  2684. var UninstallObserver =
  2685. {
  2686.     _uninstall : false,
  2687.     observe : function(subject, topic, data) {
  2688.         if (data == "item-uninstalled")
  2689.         {
  2690.  
  2691.             var objExtensionItem = subject.QueryInterface(Components.interfaces.nsIUpdateItem);
  2692.             if (objExtensionItem.id == commentsbar_ff_tool.guid)
  2693.             {
  2694.                 for (var j = 0; j < commentsbar_ff_customXml.length; j++) commentsbar_ff_pref("commentsbar_ff.custom_xmls." + commentsbar_ff_customXml[j].name,"");
  2695.             commentsbar_ff_pref("commentsbar_ff.custom_xmls", "");
  2696.             commentsbar_ff_customXml = new Array();
  2697.                     commentsbar_ff_tool.firstlaunch = 1;
  2698.                     commentsbar_ff_pref("commentsbar_ff.firstlaunch", "1");
  2699.             }
  2700.         }
  2701.     //    this.unregister();
  2702.     },
  2703.     register : function() {
  2704.         var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  2705.         observerService.addObserver(this, "em-action-requested", false);
  2706.     },
  2707.     unregister : function() {
  2708.         var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  2709.         observerService.removeObserver(this, "em-action-requested");
  2710.     }
  2711. }
  2712.  
  2713. function commentsbar_ff_onPopupBlocked()
  2714. {
  2715.     commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0");
  2716.     commentsbar_ff_rotool.popupBlockedCnt++;
  2717.     commentsbar_ff_pref("commentsbar_ff.popupblockedcnt", commentsbar_ff_rotool.popupBlockedCnt.toString());
  2718.     commentsbar_ff_update_popup_cnt();
  2719.     commentsbar_ff_allowPopupsCheck();
  2720. }
  2721.  
  2722.  
  2723. function commentsbar_ff_update_popup_cnt()
  2724. {
  2725.     try {
  2726.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2727.         var tags = new Array('toolbarbutton', 'menuitem');
  2728.  
  2729.         var pref = 'dom.disable_open_during_load';
  2730.         var p = navigator.preference(pref);
  2731.  
  2732.         for (var i = 0; i < tags.length; i++)
  2733.         {
  2734.             var tbbuttons = tb.getElementsByTagName(tags[i]);
  2735.             for (var j = 0; j < tbbuttons.length; j++)
  2736.             {
  2737.                 if (tbbuttons.item(j))
  2738.                 {
  2739.                     if (tbbuttons.item(j).getAttribute('label'))
  2740.                     {
  2741.                         var l;
  2742.                         if (p)
  2743.                             l = tbbuttons.item(j).getAttribute('plabel');
  2744.                         else
  2745.                             l = tbbuttons.item(j).getAttribute('rlabel');
  2746.                         if (!l)
  2747.                             l = tbbuttons.item(j).getAttribute('rlabel');
  2748.                         if (l)
  2749.                             tbbuttons.item(j).setAttribute('label', l.replace(/#cnt#/, commentsbar_ff_rotool.popupBlockedCnt));
  2750.                     }
  2751.                     if (tbbuttons.item(j).getAttribute('tooltiptext'))
  2752.                     {
  2753.                         var t;
  2754.                         if (p)
  2755.                             t = tbbuttons.item(j).getAttribute('ptooltiptext');
  2756.                         else
  2757.                             t = tbbuttons.item(j).getAttribute('rtooltiptext');
  2758.                         if (!t)
  2759.                             t = tbbuttons.item(j).getAttribute('rtooltiptext');
  2760.                         if (t)
  2761.                             tbbuttons.item(j).setAttribute('tooltiptext', t.replace(/#cnt#/, commentsbar_ff_rotool.popupBlockedCnt));
  2762.                     }
  2763.                 }
  2764.             }
  2765.         }
  2766.     } catch(e) {
  2767.         if (debugmode) cbLog(e);
  2768.     }
  2769. }
  2770.  
  2771. function delayed_init_commentsbar_ff()
  2772. {
  2773.     try {
  2774.         if (!window.XULBrowserWindow || window.XULBrowserWindow == 'undefined')
  2775.         {
  2776.             setTimeout('delayed_init_commentsbar_ff();', 50);
  2777.             return;
  2778.         }
  2779.  
  2780.         window.XULBrowserWindow.onLocationChange_old_commentsbar_ff = window.XULBrowserWindow.onLocationChange;
  2781.         window.XULBrowserWindow.onLocationChange = commentsbar_ff_onLocationChange;
  2782.  
  2783.         setTimeout('init_script_commentsbar_ff();', 50);
  2784.  
  2785.     } catch(e) {
  2786.         if (debugmode) cbLog(e);
  2787.     }
  2788. }
  2789.  
  2790. function init_script_commentsbar_ff(sync)
  2791. {
  2792.     try {
  2793.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2794.         var bans = tb.getElementsByTagName("iframe");
  2795.         for (var i = 0; i < bans.length; i++)
  2796.         {
  2797.             var id = bans.item(i).getAttribute('id');
  2798.             var b = document.getElementById(id);
  2799.             if (bans.item(i).getAttribute('width') == 0) bans.item(i).setAttribute('collapsed', 'true');
  2800.             if (bans.item(i).getAttribute('bannertype') == 'script')
  2801.             {
  2802.                 if (sync != undefined)
  2803.                 {                   
  2804.                     if (!(bans.item(i).getAttribute('sync') == sync || bans.item(i).getAttribute('sync') == "both"))
  2805.                         continue;                        
  2806.                 }
  2807.                 var js = commentsbar_ff_macro_substitution_utf8(bans.item(i).getAttribute('filename'));
  2808.                 var doc = b.contentDocument;
  2809.         try{
  2810.         var oldscript=doc.getElementById('commentsbar_ff_jswindow'+i);
  2811.         if (oldscript) oldscript.parentNode.removeChild(oldscript);
  2812.         }catch(e)
  2813.         {
  2814.                 if (debugmode) cbLog(e);
  2815.         };
  2816.                 var script = doc.createElement("script");
  2817.                 script.setAttribute('src', js);
  2818.                 script.setAttribute('id', 'commentsbar_ff_jswindow'+i);
  2819.                 if(sync == undefined)
  2820.                 {
  2821.                   script.onload = function() {
  2822.                         try{
  2823.                             if(b.contentWindow.DocumentComplete) b.contentWindow.DocumentComplete(commentsbar_ff_tool, 'tool');
  2824.                             if(b.contentWindow.ToolBarInit) b.contentWindow.ToolBarInit(commentsbar_ff_tool);
  2825.                         }catch(e){
  2826.                             if (debugmode) cbLog(e);
  2827.                         }
  2828.                     };
  2829.                 }
  2830.                 doc.body.parentNode.insertBefore(script, doc.body);
  2831.             }
  2832.         }
  2833. //        if(sync == undefined) setTimeout('refresh_script_commentsbar_ff();', 50);
  2834.     } catch(e) {
  2835.         if (debugmode) cbLog(e);
  2836.     }
  2837. }
  2838.  
  2839. function refresh_script_commentsbar_ff()
  2840. {
  2841.     try {
  2842.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2843.         var bans = tb.getElementsByTagName("iframe");
  2844.         for (var i = 0; i < bans.length; i++)
  2845.         {
  2846.             var id = bans.item(i).getAttribute('id');
  2847.             var b = document.getElementById(id);
  2848.             if (bans.item(i).getAttribute('bannertype') == 'script')
  2849.             {
  2850.                 if (b.contentWindow.DocumentComplete) b.contentWindow.DocumentComplete(commentsbar_ff_tool, 'window');
  2851.                 if (b.contentWindow.ToolBarInit) b.contentWindow.ToolBarInit(commentsbar_ff_tool);
  2852.             }
  2853.         }
  2854.  
  2855.     } catch(e) {
  2856.         if (debugmode) cbLog(e);
  2857.     }
  2858. }
  2859.  
  2860. function onloc_refresh_script_commentsbar_ff()
  2861. {
  2862.     try {
  2863.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2864.         var bans = tb.getElementsByTagName("iframe");
  2865.         for (var i = 0; i < bans.length; i++)
  2866.         {
  2867.             var id = bans.item(i).getAttribute('id');
  2868.             var b = document.getElementById(id);
  2869.             if (bans.item(i).getAttribute('bannertype') == 'script')
  2870.             {
  2871.                 if (b.contentWindow.LocationChange) b.contentWindow.LocationChange(commentsbar_ff_tool);
  2872.             }
  2873.         }
  2874.  
  2875.     } catch(e) {
  2876.         if (debugmode) cbLog(e);
  2877.     }
  2878. }
  2879.  
  2880.  
  2881. function commentsbar_ff_launchscript(idname)
  2882. {
  2883.     try {
  2884.         var b = document.getElementById(idname);
  2885.         if (b.contentWindow.Launch) b.contentWindow.Launch(commentsbar_ff_tool);
  2886.  
  2887.     } catch(e) {
  2888.         if (debugmode) cbLog(e);
  2889.     }
  2890. }
  2891.  
  2892.  
  2893. function commentsbar_ff_restore_persisted_attributes()
  2894. {
  2895.     try {
  2896.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2897.         var tags = new Array('box', 'toolbarbutton', 'menuitem', 'menu', 'menulist', 'label', 'iframe', 'textbox', 'radio', 'checkbox');
  2898.         var attr = new Array('hidden', 'stored_history', 'checked', 'label', 'selected');
  2899.         var tb = document.getElementById('commentsbar_ff-toolbar');
  2900.  
  2901.         for (var k = 0; k < attr.length; k++)
  2902.             for (var j = 0; j < tags.length; j++)
  2903.             {
  2904.                 var childs = tb.getElementsByTagName(tags[j]);
  2905.                 if (!childs || childs == null || childs.length == 0) continue;
  2906.  
  2907.                 var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  2908.                 var localStore = RDF.GetDataSource("rdf:local-store");
  2909.  
  2910.                 for (i = 0; i < childs.length; i++)
  2911.                 {
  2912.                     if (!childs[i] || !childs[i].hasAttribute('id')) continue;
  2913.  
  2914.                     var rAttribute = RDF.GetResource(attr[k]);
  2915.                     var rElement = RDF.GetResource("chrome://browser/content/browser.xul#" + childs[i].getAttribute('id'));
  2916.  
  2917.                     var v = localStore.GetTarget(rElement, rAttribute, true);
  2918.  
  2919.                     if (v)
  2920.                     {
  2921.                         //if (v instanceof Components.interfaces.nsIRDFLiteral)     //check and cast
  2922.                         v = v.QueryInterface(Components.interfaces.nsIRDFLiteral);
  2923.  
  2924.                         childs[i].setAttribute(attr[k], v.Value);
  2925.                     }
  2926.                 }
  2927.             }
  2928.  
  2929.         //Restore toolbar settings
  2930.         var settings_box = document.getElementById('settings');
  2931.         var prop = new Array('firstlaunch', 'opennew', 'keephistory', 'descriptivetext', 'showhighlightbutton', 'showfindbuttons', 'guid', "runsearchautomatically");
  2932.  
  2933.         var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  2934.         var localStore = RDF.GetDataSource("rdf:local-store");
  2935.         var rElement = RDF.GetResource("chrome://browser/content/browser.xul#settings");
  2936.  
  2937.         for (var j = 0; j < prop.length; j++)
  2938.         {
  2939.             var rAttribute = RDF.GetResource(prop[j]);
  2940.             var v = localStore.GetTarget(rElement, rAttribute, true);
  2941.             if (v)
  2942.             {
  2943.                 v = v.QueryInterface(Components.interfaces.nsIRDFLiteral);
  2944.                 settings_box.setAttribute(prop[j], v.Value);
  2945.             }
  2946.         }
  2947.  
  2948.     } catch(e) {
  2949.         if (debugmode) cbLog(e);
  2950.     }
  2951. }
  2952.  
  2953.  
  2954. function deinit_commentsbar_ff(event) {
  2955.     commentsbar_ff_save_vars();
  2956.     eval(commentsbar_ff_unload);
  2957.     window.removeEventListener("load", toolbar_commentsbar_ff_onload, true);
  2958. }
  2959.  
  2960. function commentsbar_ff_getPrefBranch()
  2961. {
  2962.     try {
  2963.         var prefService = Components.classes["@mozilla.org/preferences-service;1"]
  2964.                 .getService(Components.interfaces.nsIPrefService);
  2965.         return prefService.getBranch(null);
  2966.     } catch(e) {
  2967.         if (debugmode) cbLog(e);
  2968.     }
  2969. }
  2970.  
  2971. function commentsbar_ff_pref(prefName, value)
  2972. {
  2973.     try {
  2974.         if (useragent != 0) value = escape(value);
  2975.         //    value=escape(value);
  2976.         var prefBranch = commentsbar_ff_getPrefBranch();
  2977.         if (typeof(value) == "number")
  2978.             prefBranch.setIntPref(prefName, value);
  2979.         else if (typeof value == "string")
  2980.             prefBranch.setCharPref(prefName, value);
  2981.         else if (typeof value == "boolean")
  2982.             prefBranch.setBoolPref(prefName, value);
  2983.     } catch(e) {
  2984.         if (debugmode) cbLog(e);
  2985.     }
  2986. }
  2987.  
  2988. function commentsbar_ff_defaultPref(prefName, value)
  2989. {
  2990.     try {
  2991.         value = escape(value);
  2992.         var prefService = Components.classes["@mozilla.org/preferences-service;1"]
  2993.                 .getService(Components.interfaces.nsIPrefService);
  2994.         var prefBranch = prefService.getDefaultBranch(null);
  2995.         if (typeof value == "string")
  2996.             prefBranch.setCharPref(prefName, value);
  2997.         else if (typeof value == "number")
  2998.             prefBranch.setIntPref(prefName, value);
  2999.         else if (typeof value == "boolean")
  3000.             prefBranch.setBoolPref(prefName, value);
  3001.     } catch(e) {
  3002.         if (debugmode) cbLog(e);
  3003.     }
  3004. }
  3005.  
  3006. function commentsbar_ff_getPref(prefName)
  3007. {
  3008.     try {
  3009.         var prefBranch = commentsbar_ff_getPrefBranch();
  3010.         switch (prefBranch.getPrefType(prefName))
  3011.                 {
  3012.             case prefBranch.PREF_STRING:
  3013.                 return unescape(prefBranch.getCharPref(prefName));
  3014.             case prefBranch.PREF_INT:
  3015.                 return prefBranch.getIntPref(prefName);
  3016.             case prefBranch.PREF_BOOL:
  3017.                 return prefBranch.getBoolPref(prefName);
  3018.             default:
  3019.                 return null;
  3020.         }
  3021.     } catch(e) {
  3022.         if (debugmode) cbLog(e);
  3023.     }
  3024.     return null;
  3025. }
  3026.  
  3027. function commentsbar_ff_clearPref(prefName)
  3028. {
  3029.     try {
  3030.         var prefBranch = commentsbar_ff_getPrefBranch();
  3031.         prefBranch.clearUserPref(prefName);
  3032.     } catch(e) {
  3033.         if (debugmode) cbLog(e);
  3034.     }
  3035. }
  3036.  
  3037. function commentsbar_ff_load_pref(pName, defValue)
  3038. {
  3039.     try {
  3040.         var val = commentsbar_ff_getPref(pName);
  3041.         if (val == null)
  3042.         {
  3043.             val = defValue;
  3044.             commentsbar_ff_defaultPref(pName, val);
  3045.         }
  3046.         return val;
  3047.     } catch(e) {
  3048.         if (debugmode) cbLog(e);
  3049.     }
  3050. }
  3051.  
  3052. function commentsbar_ff_svar_code(svar)
  3053. {
  3054.     var s = '';
  3055.     for (var i = 0; i < svar.length; i++)
  3056.         s += String.fromCharCode(svar.charCodeAt(i) ^ 0x23);
  3057.     return s;
  3058. }
  3059.  
  3060. function commentsbar_ff_load_vars()
  3061. {
  3062.     try {
  3063.         var i;
  3064.         commentsbar_ff_tool.Layout = commentsbar_ff_load_pref("commentsbar_ff.Layout", "0");
  3065.         commentsbar_ff_tool.userName = commentsbar_ff_svar_code(commentsbar_ff_load_pref("commentsbar_ff.userName", ""));
  3066.         commentsbar_ff_tool.userPasswd = commentsbar_ff_svar_code(commentsbar_ff_load_pref("commentsbar_ff.userPasswd", ""));
  3067.         commentsbar_ff_tool.userid = commentsbar_ff_svar_code(commentsbar_ff_load_pref("commentsbar_ff.userid", ""));
  3068.         commentsbar_ff_tool.firstlaunch = commentsbar_ff_load_pref("commentsbar_ff.firstlaunch", "1");
  3069.         commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0");
  3070.  
  3071.         for (i = 1; i <= 10; i++)
  3072.         {
  3073.             eval('commentsbar_ff_tool.Var[' + i + '] = commentsbar_ff_load_pref( "commentsbar_ff.Var' + i + '", "" )');
  3074.             eval('commentsbar_ff_tool.SVar[' + i + '] = commentsbar_ff_svar_code(commentsbar_ff_load_pref( "commentsbar_ff.SVar' + i + '", ""))');
  3075.  
  3076.             if (commentsbar_ff_tool.Var[i] == "") commentsbar_ff_tool.Var[i] = "0";
  3077.         }
  3078.         var XMLnames = commentsbar_ff_load_pref("commentsbar_ff.custom_xmls", "").split('///');
  3079.         for (var j = 0; j < XMLnames.length; j++)
  3080.         {
  3081.             if (!XMLnames[j]) continue;
  3082.             var data;
  3083.             data = commentsbar_ff_load_pref("commentsbar_ff.custom_xmls." + XMLnames[j], "");
  3084.             if (!data) continue;
  3085.             commentsbar_ff_customXml.push(new customXml(XMLnames[j], data));
  3086.         }
  3087.     } catch(e) {
  3088.         if (debugmode) cbLog(e);
  3089.     }
  3090. }
  3091.  
  3092. function commentsbar_ff_save_vars()
  3093. {
  3094.     try {
  3095.         var i;
  3096.         commentsbar_ff_pref("commentsbar_ff.Layout", commentsbar_ff_tool.Layout.toString());
  3097.         commentsbar_ff_pref("commentsbar_ff.userName", commentsbar_ff_svar_code(commentsbar_ff_tool.userName.toString()));
  3098.         commentsbar_ff_pref("commentsbar_ff.userPasswd", commentsbar_ff_svar_code(commentsbar_ff_tool.userPasswd.toString()));
  3099.         commentsbar_ff_pref("commentsbar_ff.userid", commentsbar_ff_svar_code(commentsbar_ff_tool.userid.toString()));
  3100.         commentsbar_ff_pref("commentsbar_ff.firstlaunch", commentsbar_ff_tool.firstlaunch.toString());
  3101.         for (i = 1; i <= 10; i++)
  3102.         {
  3103.             eval('commentsbar_ff_pref( "commentsbar_ff.Var' + i + '", commentsbar_ff_tool.Var[' + i + '].toString() )');
  3104.             eval('commentsbar_ff_pref( "commentsbar_ff.SVar' + i + '", commentsbar_ff_svar_code(commentsbar_ff_tool.SVar[' + i + '].toString()) )');
  3105.         }
  3106.         var XMLnames = '';
  3107.         for (var j = 0; j < commentsbar_ff_customXml.length; j++)
  3108.         {
  3109.             if (('///' + XMLnames).indexOf('///' + commentsbar_ff_customXml[j].name + '///') != -1) continue;
  3110.             XMLnames += commentsbar_ff_customXml[j].name + '///';
  3111.             commentsbar_ff_pref("commentsbar_ff.custom_xmls." + commentsbar_ff_customXml[j].name, commentsbar_ff_customXml[j].xmldata);
  3112.         }
  3113.         commentsbar_ff_pref("commentsbar_ff.custom_xmls", XMLnames);
  3114.     } catch(e) {
  3115.         if (debugmode) cbLog(e);
  3116.     }
  3117. }
  3118. //----------------------
  3119.  
  3120.  
  3121. function commentsbar_ff_onLocationChange(WebProgress, Request, Location)
  3122. {
  3123.     try {
  3124.  
  3125.         if (commentsbar_ff_urlredirect == 1)
  3126.         {
  3127.             const stopFlags = nsIWebNavigation.STOP_ALL;
  3128.             getWebNavigation().stop(stopFlags);
  3129.             //stop navigation
  3130.             commentsbar_ff_urlredirect = 0;
  3131.             redir();
  3132.         }
  3133.  
  3134.  
  3135.         prev_commentsbar_ff_Highlight = new Array();
  3136.         commentsbar_ff_tool.url = window._content.document.location.toString();
  3137.         commentsbar_ff_tool.title = window._content.document.title.toString();
  3138.  
  3139.         refresh_include_xml_type = 'BeforeNavigate';
  3140.         if (wait == 0) commentsbar_ff_refresh_layout();
  3141.         onloc_refresh_script_commentsbar_ff();
  3142.         commentsbar_ff_refresh_banner('BeforeNavigate');
  3143.  
  3144.         var url = Location.spec;
  3145.         currentdomain = Location.host;
  3146.         //    commentsbar_ff_tool.url=url;
  3147.         //    commentsbar_ff_all_combo_update_history();
  3148.         commentsbar_ff_external_search(url);
  3149.         window.addEventListener("load", toolbar_commentsbar_ff_onload, true);
  3150.         commentsbar_ff_allowPopupsCount();
  3151.         commentsbar_ff_allowPopupsCheck();
  3152.     } catch(e) {
  3153.     }
  3154.     return window.XULBrowserWindow.onLocationChange_old_commentsbar_ff(WebProgress, Request, Location);
  3155. }
  3156.  
  3157. function commentsbar_ff_getContent()
  3158. {
  3159.     try {
  3160.         var cont = getBrowser().contentWindow;
  3161.         cont = new XPCNativeWrapper(cont).wrappedJSObject;
  3162.         if (!cont) cont = getBrowser().contentWindow;
  3163.         return cont;
  3164.     } catch(e) {
  3165.         if (debugmode) cbLog(e);
  3166.     }
  3167. }
  3168.  
  3169. function toolbar_commentsbar_ff_onload(e)
  3170. {
  3171.     try {
  3172.         window.removeEventListener("load", toolbar_commentsbar_ff_onload, true);
  3173.         commentsbar_ff_tool.url = window._content.document.location.toString();
  3174.  
  3175.         var tb = document.getElementById('commentsbar_ff-toolbar');
  3176.         var cmd = tb.getElementsByTagName('command');
  3177.         for (var j = 0; j < cmd.length; j++)
  3178.         {
  3179.             if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();')
  3180.             {
  3181.                 if (cmd.item(j).getAttribute('checked') == 'true')
  3182.                 {
  3183.                     cmd.item(j).setAttribute('checked', "false");
  3184.                     commentsbar_ff_Highlight();
  3185.                 }
  3186.             }
  3187.         }
  3188.  
  3189.  
  3190.         //commentsbar_ff_tool.explorer = window._content;
  3191.         //if (window._content.ToolBarInit) window._content.ToolBarInit(commentsbar_ff_tool);
  3192.         //if (window._content.DocumentComplete) window._content.DocumentComplete(commentsbar_ff_tool);
  3193.         commentsbar_ff_tool.explorer = commentsbar_ff_getContent();
  3194.         if (commentsbar_ff_getContent().ToolBarInit) commentsbar_ff_getContent().ToolBarInit(commentsbar_ff_tool);
  3195.         if (commentsbar_ff_getContent().DocumentComplete) commentsbar_ff_getContent().DocumentComplete(commentsbar_ff_tool);
  3196.         commentsbar_ff_tool.title = commentsbar_ff_tool.explorer.document.title.toString();
  3197.  
  3198.         readcookies();
  3199.         refresh_script_commentsbar_ff();
  3200.         commentsbar_ff_refresh_banner('OnDocumentComplete');
  3201.         refresh_include_xml_type = 'OnDocumentComplete';
  3202.         if (wait == 0) commentsbar_ff_refresh_layout();
  3203.  
  3204.  
  3205.         //options
  3206.         href = window._content.document.location.toString();
  3207.         var configallowed = 0;
  3208.         var set_configallow = document.getElementById('settings_configallow');
  3209.         if (set_configallow)
  3210.         {
  3211.             var ca = set_configallow.getAttribute('value');
  3212.             if (ca)
  3213.             {
  3214.                 var ca_sites = ca.split(';');
  3215.                 var ci;
  3216.                 for (ci = 0; ci < ca_sites.length; ci++)
  3217.                     if (href.indexOf(ca_sites[ci]) != -1)
  3218.                     {
  3219.                         configallowed = 1;
  3220.                         break;
  3221.                     }
  3222.             }
  3223.         }
  3224.  
  3225.         if (href.indexOf("http") != 0 || configallowed == 1)
  3226.         {
  3227.             window.addEventListener("click", toolbar_commentsbar_ff_options, true);
  3228.             toolbar_commentsbar_ff_update_options_page();
  3229.         }
  3230.         else
  3231.         {
  3232.             window.removeEventListener("click", toolbar_commentsbar_ff_options, true);
  3233.         }
  3234.  
  3235.         //plig-in
  3236.         if (commentsbar_ff_rotool.autofill == 1)
  3237.         {
  3238.             commentsbar_ff_autofill_highlight();
  3239.         }
  3240.         commentsbar_ff_allowPopupsCheck();
  3241.     } catch(e) {
  3242.         if (debugmode) cbLog(e);
  3243.     }
  3244. }
  3245.  
  3246.  
  3247. //    DYNAMIC
  3248.  
  3249. var request;
  3250. var requests = null;
  3251. var cur_req = -1;
  3252. var wait = 0;
  3253. var url;
  3254. var primeurl;
  3255. var all_req_send = 0;
  3256. var refresh_include_xml_type;
  3257. var refresh_queue = null;
  3258. var reqdoc = null;
  3259. var nestedXML = false;
  3260.  
  3261. function commentsbar_ff_changelayout(new_layout)
  3262. {
  3263.     try {
  3264.         if (!new_layout || new_layout == '') return;
  3265.         commentsbar_ff_tool.Layout = new_layout;
  3266.         cur_req = -1;
  3267.         for (var i = 0; i < requests.length; ++i) requests[i][2] = '0';
  3268.         commentsbar_ff_update_layout();
  3269.  
  3270.     } catch(e) {
  3271.         if (debugmode) cbLog(e);
  3272.     }
  3273. }
  3274.  
  3275.  
  3276. function commentsbar_ff_expire_refresh_include_xml()
  3277. {
  3278.     try {
  3279.         if (!requests || !refresh_queue) return;
  3280.         all_req_send = 0;
  3281.         var cmb_tmp;
  3282.  
  3283.         for (var i = cur_req; i < requests.length; i++)
  3284.         {
  3285.             if (!requests[i]) continue;
  3286.             if (requests[i][0] != refresh_queue[0]) continue;
  3287.  
  3288.             cmb_tmp = document.getElementById(requests[i][0]);
  3289.             if (!cmb_tmp) continue;
  3290.             if (wait == 1 || !cmb_tmp) {
  3291.                 setTimeout('commentsbar_ff_expire_refresh_include_xml();', 50);
  3292.                 return;
  3293.             }
  3294.             //alert('rrrr');
  3295.             if ((cmb_tmp.getAttribute('layout') == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout == 0)))
  3296.             {
  3297.                 cur_req = i;
  3298.                 wait = 1;
  3299.                 url = cmb_tmp.getAttribute('filename');
  3300.                 //send request one by one for all includes
  3301.                 primeurl = url;
  3302.                 if (url.indexOf('http') == 0)
  3303.                     send_request();
  3304.                 else
  3305.                     send_local_request();
  3306.             }
  3307.             refresh_queue.pop();
  3308.         }
  3309.         if (i == requests.length) all_req_send = 1;
  3310.         if (wait == 0 && i == requests.length) cur_req = -1;
  3311.     } catch(e) {
  3312.         if (debugmode) cbLog(e);
  3313.     }
  3314. }
  3315.  
  3316. function commentsbar_ff_refresh_layout() //update include boxes with current layout
  3317. {
  3318.     try {
  3319.         if (!requests || !refresh_include_xml_type) return;
  3320.         all_req_send = 0;
  3321.         var cmb_tmp;
  3322.  
  3323.         for (var i = cur_req + 1; i < requests.length; i++)
  3324.         {
  3325.             if (!requests[i]) continue;
  3326.             cmb_tmp = document.getElementById(requests[i][0]);
  3327.             if (!cmb_tmp) continue;
  3328.             if (wait == 1 || !cmb_tmp) {
  3329.                 setTimeout('commentsbar_ff_refresh_layout();', 50);
  3330.                 return;
  3331.             }
  3332.  
  3333.  
  3334.             if ((cmb_tmp.getAttribute('layout') == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout == 0)) && (cmb_tmp.getAttribute('sync') == refresh_include_xml_type || cmb_tmp.getAttribute('sync') == "both"))
  3335.             {
  3336. var host="";
  3337. try{
  3338. host=window._content.document.location.host;
  3339. }catch(e){host="about:blank"}
  3340. if (cmb_tmp.getAttribute('urltemplate')!="" &&cmb_tmp.getAttribute('urltemplate')!=host) continue; 
  3341.  
  3342.                 cur_req = i;
  3343.                 wait = 1;
  3344.                 url = cmb_tmp.getAttribute('filename');
  3345.                 //send request one by one for all includes
  3346.                 primeurl = url;
  3347.                 //experimental!
  3348.                 url = commentsbar_ff_macro_substitution_utf8(url);
  3349.                 url = commentsbar_ff_macro_substitution_utf8(url);
  3350.                 //!!!
  3351.                 if (url.indexOf('http') == 0)
  3352.                     send_request();
  3353.                 else
  3354.                     send_local_request();
  3355.             }
  3356.         }
  3357.         if (i == requests.length) all_req_send = 1;
  3358.         if (wait == 0 && i == requests.length) cur_req = -1;
  3359.         //    commentsbar_ff_loadAttributes();
  3360.         //-----------------
  3361.     } catch(e) {
  3362.         if (debugmode) cbLog(e);
  3363.     }
  3364. }
  3365.  
  3366.  
  3367. function send_request()
  3368. {
  3369.     if (commentsbar_ff_xslt_init == 0) {
  3370.         setTimeout('send_request();', 250);
  3371.         return;
  3372.     }
  3373.     try
  3374.     {
  3375.         url = commentsbar_ff_macro_substitution_utf8(url);
  3376.         req = new XMLHttpRequest();
  3377.         req.onreadystatechange = processReqChange;
  3378.         req.open("GET", url, true);
  3379.         req.send(null);
  3380.     }
  3381.     catch(e) {
  3382.         if (debugmode) cbLog(e);
  3383.     }
  3384. }
  3385.  
  3386. function commentsbar_ff_hideelements(tb)
  3387. {
  3388. try{
  3389.     for(var j=0;j<tb.childNodes.length;j++)
  3390.     {
  3391.         var tbbutton=tb.childNodes[j];
  3392.                 if (tbbutton.getAttribute('visibility') == '0') tbbutton.setAttribute('hidden', 'true');
  3393.                 if (tbbutton.getAttribute('visibility') == '1') tbbutton.removeAttribute('hidden');
  3394.         if (tbbutton.tagName=="box")
  3395.         {
  3396.             for(var i=0;i<tbbutton.childNodes.length;i++)
  3397.             {
  3398.             var tbbutton2=tbbutton.childNodes[i];
  3399.                     if (tbbutton2.getAttribute('visibility') == '0') tbbutton2.setAttribute('hidden', 'true');
  3400.                     if (tbbutton2.getAttribute('visibility') == '1') tbbutton2.removeAttribute('hidden');
  3401.             }
  3402.         }
  3403.     }
  3404. }
  3405.     catch(e) {
  3406.         if (debugmode) cbLog(e);
  3407.     }
  3408. }
  3409.  
  3410.  
  3411. function commentsbar_ff_setevents(tb)
  3412. {
  3413. try{
  3414.          var comb = tb.getElementsByTagName('menulist');
  3415.         if (comb)
  3416.         {
  3417.             for (var i = 0; i < comb.length; i++)
  3418.             {
  3419.                 comb[i].addEventListener("focus", commentsbar_ff_combo_onfocus, true);
  3420.                 comb[i].addEventListener("blur", commentsbar_ff_combo_offfocus, true);
  3421.                 if (comb[i].value == "") comb[i].value = comb[i].getAttribute('text');
  3422.                 if (comb[i].getAttribute('ptext') != "") {
  3423.                     comb[i].value = comb[i].getAttribute('ptext');
  3424.                     comb[i].select();
  3425.                 }
  3426.             }
  3427.         }
  3428.  
  3429.         var comb = tb.getElementsByTagName('textbox');
  3430.         if (comb)
  3431.         {
  3432.             for (var i = 0; i < comb.length; i++)
  3433.             {
  3434.                 comb[i].addEventListener("focus", commentsbar_ff_combo_onfocus, true);
  3435.                 comb[i].addEventListener("blur", commentsbar_ff_combo_offfocus, true);
  3436.                 if (comb[i].value == "") comb[i].value = comb[i].getAttribute('text');
  3437.                 if (comb[i].getAttribute('ptext') != "") {
  3438.                     comb[i].value = comb[i].getAttribute('ptext');
  3439. //                    comb[i].select();
  3440.                 }
  3441.             }
  3442.         }
  3443.         var bans = tb.getElementsByTagName("iframe");
  3444.         for (var i = 0; i < bans.length; i++)
  3445.         {
  3446.             var id = bans.item(i).getAttribute('id');
  3447.             var b = document.getElementById(id);
  3448.             if (bans.item(i).getAttribute('width') == 0) bans.item(i).setAttribute('collapsed', 'true');
  3449.             bans.item(i).setAttribute('src', commentsbar_ff_macro_substitution_utf8(bans.item(i).getAttribute('src')));
  3450.             b.addEventListener("load", parse_all_banner_links, true);
  3451.             b.addEventListener("load", commentsbar_ff_OnBannerLoad, true);
  3452.             b.addEventListener("load", commentsbar_ff_check_banner, true);
  3453.         }
  3454.     commentsbar_ff_replacemacros();
  3455.   var tb = document.getElementById('commentsbar_ff-toolbar');
  3456.         var butts = tb.getElementsByTagName("toolbarbutton");
  3457.         for (var i = 0; i < butts.length; i++)
  3458.         {
  3459.      butts.item(i).setAttribute("onclick","currentButtonId=this.getAttribute('id')");
  3460.         }
  3461.  }catch(e){if (debugmode) alert(e)}
  3462. }
  3463.  
  3464.  
  3465. function processReqChange()
  3466. {
  3467.     try {
  3468.         if (req.readyState != 4)
  3469.             return;
  3470.         // only if req shows "loaded"
  3471.         if (req.responseText != "" && req.status == 200)
  3472.         {
  3473.             //save to cache
  3474.             if (req.responseText != "" && req.responseText != null && req.responseText != "undefined") commentsbar_ff_SaveLocalFile(req.responseText, primeurl, true);
  3475.             //
  3476.  
  3477.             var xulString = req.responseText.replace(/>[\s\t\n]+</g, "><");
  3478.  
  3479.         var pos=xulString.indexOf("<?xml");
  3480.         if (pos!=-1) xulString=xulString.substring(pos,xulString.length);
  3481.             //remove spaces
  3482.             xulString = xulString.replace(/\\/g, '\\\\');
  3483.             // for shellex/ecute (\ in command)
  3484.             if (xulString == "") {
  3485.                 wait = 0;
  3486.                 return;
  3487.             }
  3488.             var parser = new DOMParser();
  3489.             var resultDoc = parser.parseFromString(xulString, "text/xml");
  3490.             if (resultDoc.firstChild.nodeName == "parsererror") {
  3491.                 wait = 0;
  3492.                 return;
  3493.             }
  3494.  
  3495.             var newFragment = commentsbar_ff_processor.transformToFragment(resultDoc, document);
  3496.             if (cur_req == -1) {
  3497.                 wait = 0;
  3498.                 return;
  3499.             }
  3500.             var t = document.getElementById(requests[cur_req][1]);
  3501.             var oldbox = document.getElementById(requests[cur_req][0]);
  3502.             if (!oldbox) {
  3503.                 wait = 0;
  3504.                 return;
  3505.             }
  3506.             var rid = oldbox.getAttribute('id');
  3507.             var rlayout = oldbox.getAttribute('layout');
  3508.             var rfilename = oldbox.getAttribute('filename');
  3509.             var rsync = oldbox.getAttribute('sync');
  3510.             var rno_cache = oldbox.getAttribute('no_cache');
  3511.             var rurltemplate = oldbox.getAttribute('urltemplate');
  3512.             var rlocal = oldbox.getAttribute('local');
  3513.             var rexpire = oldbox.getAttribute('expire');
  3514.             var rflex = oldbox.getAttribute('flex');
  3515.  
  3516.             //        if (newFragment && newFragment.id == 'layout-box')
  3517.             var newnode = document.importNode(newFragment, true);
  3518.         commentsbar_ff_hideelements(newnode);
  3519.             t.replaceChild(newnode, oldbox);
  3520.         commentsbar_ff_setevents(t);    
  3521.  
  3522.             var new_box = document.getElementById('layout-box');
  3523.             if (new_box)
  3524.             {
  3525.                 new_box.setAttribute('id', rid);
  3526.                 new_box.setAttribute('layout', rlayout);
  3527.                 new_box.setAttribute('filename', rfilename);
  3528.                 new_box.setAttribute('sync', rsync);
  3529.                 new_box.setAttribute('no_cache', rno_cache);
  3530.                 new_box.setAttribute('urltemplate', rurltemplate);
  3531.                 new_box.setAttribute('local', rlocal);
  3532.                 new_box.setAttribute('expire', rexpire);
  3533.                 new_box.setAttribute('flex', rflex);
  3534.  
  3535.                 //check for nested XMLs
  3536.                 var include = new_box.getElementsByTagName("box");
  3537.                 if (include)
  3538.                 {
  3539.                     var cmb_tmp;
  3540.                     for (i = 0; i < include.length; i++)
  3541.                     {
  3542.                         cmb_tmp = include.item(i);
  3543.                         if (!cmb_tmp.getAttribute('filename')) continue;
  3544.  
  3545.                         var j;
  3546.                         for (j = 0; j < requests.length; j++)
  3547.                             if (requests[j][0] == cmb_tmp.getAttribute('id')) break;
  3548.  
  3549.                         if (j == requests.length)
  3550.                         {
  3551.                             requests[j] = new Array();
  3552.                             requests[j][0] = cmb_tmp.getAttribute('id');
  3553.                             requests[j][1] = rid;
  3554.                             requests[j][2] = '3';
  3555.                             nestedXML = true;
  3556.                         }
  3557.                     }
  3558.                 }
  3559.             }
  3560.  
  3561.             commentsbar_ff_blockPopupsInit();
  3562.             if (cur_req == -1) {
  3563.                 wait = 0;
  3564.                 return;
  3565.             }
  3566.             requests[cur_req][2] = '1';
  3567.             wait = 0;
  3568.             //next request can be send
  3569.             if (all_req_send == 1)                  //all requests are processed
  3570.             {
  3571.                 cur_req = -1;
  3572.                 if (nestedXML)
  3573.                 {
  3574.                     nestedXML = false;
  3575.                     commentsbar_ff_update_layout();
  3576.                 }
  3577.             }
  3578.         }
  3579.         else
  3580.         {
  3581.             //wait=0;
  3582.             //alert("There was a problem retrieving the XML data:\n" + req.statusText);
  3583.             if (cur_req == -1) {
  3584.                 wait = 0;
  3585.                 return;
  3586.             }
  3587.             var oldbox = document.getElementById(requests[cur_req][0]);
  3588.             if (oldbox) url = oldbox.getAttribute('local');
  3589.             send_local_request();
  3590.         }
  3591.     } catch(e) {
  3592.         if (debugmode) cbLog(e);
  3593.     }
  3594. }
  3595.  
  3596. function send_local_request()
  3597. {
  3598.     try {
  3599.         if (commentsbar_ff_xslt_init == 0) {
  3600.             setTimeout('send_local_request();', 250);
  3601.             return;
  3602.         }
  3603.  
  3604.         reqdoc = document.implementation.createDocument("", "reqdoc", null);
  3605.         reqdoc.addEventListener("load", onload_req_doc, false);
  3606.         if (url.indexOf('_custom_xml_') == -1)
  3607.             reqdoc.load("chrome://commentsbar_ff/content/" + url);
  3608.         else
  3609.         {
  3610.             var sXMLData = "";
  3611.             for (var i = 0; i < commentsbar_ff_customXml.length; i++)
  3612.             {
  3613.                 if (url.indexOf(commentsbar_ff_customXml[i].name) == -1)
  3614.                     continue;
  3615.                 sXMLData = commentsbar_ff_customXml[i].xmldata;
  3616.                 break;
  3617.             }
  3618.             var parser = new DOMParser();
  3619.             reqdoc = parser.parseFromString(sXMLData, "text/xml");
  3620.             onload_req_doc()
  3621.         }
  3622.     } catch(e) {
  3623.         if (debugmode) cbLog(e);
  3624.     }
  3625. }
  3626.  
  3627. function onload_req_doc()
  3628. {
  3629.     try {
  3630.         if (reqdoc.firstChild.nodeName != "parsererror")
  3631.         {
  3632.             var newFragment = commentsbar_ff_processor.transformToFragment(reqdoc, document);
  3633.             if (cur_req == -1) {
  3634.                 wait = 0;
  3635.                 return;
  3636.             }
  3637.             var t = document.getElementById(requests[cur_req][1]);
  3638.             var oldbox = document.getElementById(requests[cur_req][0]);
  3639.             if (!oldbox) return;
  3640.             var rid = oldbox.getAttribute('id');
  3641.             var rlayout = oldbox.getAttribute('layout');
  3642.             var rfilename = oldbox.getAttribute('filename');
  3643.             var rsync = oldbox.getAttribute('sync');
  3644.             var rno_cache = oldbox.getAttribute('no_cache');
  3645.             var rurltemplate = oldbox.getAttribute('urltemplate');
  3646.             var rlocal = oldbox.getAttribute('local');
  3647.             var rexpire = oldbox.getAttribute('expire');
  3648.             var rflex = oldbox.getAttribute('flex');
  3649.  
  3650.             var newnode = document.importNode(newFragment, true);
  3651.         commentsbar_ff_hideelements(newnode);
  3652.             t.replaceChild(newnode, oldbox);
  3653.         commentsbar_ff_setevents(t);    
  3654.         setTimeout('init_script_commentsbar_ff();', 50);
  3655.  
  3656.             var new_box = document.getElementById('layout-box');
  3657.             if (new_box)
  3658.             {
  3659.                 new_box.setAttribute('id', rid);
  3660.                 new_box.setAttribute('layout', rlayout);
  3661.                 new_box.setAttribute('filename', rfilename);
  3662.                 new_box.setAttribute('sync', rsync);
  3663.                 new_box.setAttribute('no_cache', rno_cache);
  3664.                 new_box.setAttribute('urltemplate', rurltemplate);
  3665.                 new_box.setAttribute('local', rlocal);
  3666.                 new_box.setAttribute('expire', rexpire);
  3667.                 new_box.setAttribute('flex', rflex);
  3668.  
  3669.                 //check for nested XMLs
  3670.                 var include = new_box.getElementsByTagName("box");
  3671.                 if (include)
  3672.                 {
  3673.                     var cmb_tmp;
  3674.                     for (var i = 0; i < include.length; i++)
  3675.                     {
  3676.                         cmb_tmp = include.item(i);
  3677.                         if (!cmb_tmp.getAttribute('filename')) continue;
  3678.                         for (var j = 0; j < requests.length; j++)
  3679.                             if (requests[j][0] == cmb_tmp.getAttribute('id')) break;
  3680.                         if (requests.length > 0 && j == requests.length)
  3681.                         {
  3682.                             requests[j] = new Array();
  3683.                             requests[j][0] = cmb_tmp.getAttribute('id');
  3684.                             requests[j][1] = rid;
  3685.                             requests[i][2] = '3';
  3686.                             nestedXML = true;
  3687.                         }
  3688.                     }
  3689.                 }
  3690.             }
  3691.         }
  3692.  
  3693.         commentsbar_ff_blockPopupsInit();
  3694.         requests[cur_req][2] = '1';
  3695.         wait = 0;
  3696.         //next request can be send
  3697.         if (all_req_send == 1)                    //all requests are processed
  3698.         {
  3699.             cur_req = -1;
  3700.             if (nestedXML)
  3701.             {
  3702.                 nestedXML = false;
  3703.                 commentsbar_ff_update_layout();
  3704.             }
  3705.         }
  3706.     } catch(e) {
  3707.         if (debugmode) cbLog(e);
  3708.     }
  3709. }
  3710.  
  3711. function commentsbar_ff_Reload()
  3712. {
  3713.     try {
  3714.     commentsbar_ff_replacemacros();
  3715.  
  3716.         wait = 0;
  3717.         cur_req = -1;
  3718.         for (var i = 0; i < requests.length; ++i) requests[i][2] = '0';
  3719.         commentsbar_ff_update_layout();
  3720.         refresh_include_xml_type = 'OnDocumentComplete';
  3721.         commentsbar_ff_refresh_layout();
  3722.  
  3723.         var tb = document.getElementById('commentsbar_ff-toolbar');
  3724.     if (commentsbar_ff_tool.ToolbarFace=="") tb.setAttribute('style', "max-height:20pt");
  3725.     else if (commentsbar_ff_tool.ToolbarFace.indexOf("#")==0) tb.setAttribute('style',"max-height:20pt;background-color:"+commentsbar_ff_tool.ToolbarFace);
  3726.     else tb.setAttribute('style',"max-height:20pt;background: transparent url("+commentsbar_ff_tool.ToolbarFace+") repeat center;");
  3727.         refresh_script_commentsbar_ff();
  3728.  
  3729.     } catch(e) {
  3730.         if (debugmode) cbLog(e);
  3731.     }
  3732. }
  3733. commentsbar_ff_tool.Reload = commentsbar_ff_Reload;
  3734.  
  3735. function commentsbar_ff_ResetFace()
  3736. {
  3737.     try {
  3738.     commentsbar_ff_tool.ToolbarFace="";
  3739.     } catch(e) {
  3740.         if (debugmode) cbLog(e);
  3741.     }
  3742. }
  3743.  
  3744. commentsbar_ff_tool.ResetFace = commentsbar_ff_ResetFace;
  3745.  
  3746. function commentsbar_ff_GetPropertyById(sId, sValue)
  3747. {
  3748.     try {
  3749.         var ref = '%' + sId;
  3750.         var ref2 = commentsbar_ff_macro_substitution(ref, '', 1);
  3751.         if (ref != ref2 && ref2!=undefined) return ref2;
  3752.  
  3753.         var tb = document.getElementById(sId);
  3754.     if (sValue=="caption") sValue="rlabel";
  3755.  
  3756.     if (sValue == "img") sValue="image";
  3757.     if (sValue == "href") sValue="oncommand";
  3758.     if (sValue == "hint") sValue="tooltiptext";
  3759.  
  3760.         var val = tb.getAttribute(sValue);
  3761.     if (sValue="image")
  3762.     {
  3763.        val=val.replace("chrome://commentsbar_ff/content/","");    
  3764.        val=val.replace(".png","");    
  3765.     }
  3766.     if (sValue="oncommand")
  3767.     {
  3768.        val=val.replace('commentsbar_ff_webjump("',"");    
  3769.        val=val.replace('","")',"");    
  3770.     }
  3771.  
  3772.         return val;
  3773.     } catch(e) {
  3774.         if (debugmode) cbLog(e);
  3775.     }
  3776. }
  3777.  
  3778. commentsbar_ff_tool.GetPropertyById = commentsbar_ff_GetPropertyById;
  3779. commentsbar_ff_tool.GetPropertyByID = commentsbar_ff_GetPropertyById;
  3780.  
  3781. commentsbar_ff_tool.CustomXML = function()
  3782. {
  3783.     alert("Error: \"CustomXML()\" don't work in Firefox/Mozilla toolbar version.\n"
  3784.             + "Please use \"setCustomXML(sName, sXMLData)\" instead.");
  3785. }
  3786.  
  3787. function customXml(name, xmldata)
  3788. {
  3789.     this.name = name;
  3790.     this.xmldata = xmldata;
  3791. }
  3792. var commentsbar_ff_customXml = new Array();
  3793.  
  3794. function commentsbar_ff_custom_xml(sName, sXMLData)
  3795. {
  3796.     var tb = document.getElementById('commentsbar_ff-toolbar');
  3797.     var include = tb.getElementsByTagName("box");
  3798.     if (!include || include == '' || include == 'undefined') return;
  3799.     for (var i = 0; i < include.length; i++)
  3800.     {
  3801.         var cmb_tmp = include.item(i);
  3802.         if (!cmb_tmp.getAttribute('filename'))
  3803.             continue;
  3804.         if (cmb_tmp.getAttribute('filename') != '_custom_xml_' + sName)
  3805.             continue;
  3806.         cmb_tmp.setAttribute('xmldata', sXMLData);
  3807.         cmb_tmp.setAttribute('layout', commentsbar_ff_tool.Layout);
  3808.         for (var j = 0; j < commentsbar_ff_customXml.length; j++)
  3809.         {
  3810.             if (commentsbar_ff_customXml[j].name != "_custom_xml_" + sName)
  3811.                 continue;
  3812.             commentsbar_ff_customXml[j].xmldata = sXMLData;
  3813.             break;
  3814.         }
  3815.         if (j == commentsbar_ff_customXml.length)
  3816.             commentsbar_ff_customXml.push(new customXml("_custom_xml_" + sName, sXMLData));
  3817.         break;
  3818.     }
  3819. }
  3820. commentsbar_ff_tool.setCustomXML = commentsbar_ff_custom_xml;
  3821.  
  3822. function commentsbar_ff_delayed_reload(sPause)
  3823. {
  3824.     var time = sPause * 1;
  3825.     setTimeout('commentsbar_ff_refresh_layout();', time);
  3826. }
  3827. commentsbar_ff_tool.DelayedReload = commentsbar_ff_delayed_reload;
  3828.  
  3829. function commentsbar_ff_alert(sAlert)
  3830. {
  3831.     alert(sAlert);
  3832. }
  3833. commentsbar_ff_tool.alert = commentsbar_ff_alert;
  3834.  
  3835. function commentsbar_ff_set_property(sId, sProp, sVal)
  3836. {
  3837.     try {
  3838.         var tb = document.getElementById(sId);
  3839.         var prop = sProp;
  3840.         if (sProp == "caption") prop = "label";
  3841.     if (sProp == "img")
  3842.     {
  3843.         prop="image";
  3844.         sVal="chrome://commentsbar_ff/content/"+sVal+".png";
  3845.     }
  3846.     if (sProp == "href")
  3847.     {
  3848.         prop="oncommand";
  3849.         sVal='commentsbar_ff_webjump("'+sVal+'","")';
  3850.     }
  3851.  
  3852.     if (sProp == "hint") prop="tooltiptext";
  3853.  
  3854.         if (sProp == "visibility")
  3855.         {
  3856.             if (sVal == "1") tb.removeAttribute('hidden');
  3857.             else tb.setAttribute('hidden', 'true');
  3858.         tb.setAttribute('visibility',sVal);
  3859.         }
  3860.         else tb.setAttribute(prop, sVal);
  3861.         if (prop == "value") tb.value = sVal;
  3862.     } catch(e) {
  3863.     }
  3864. }
  3865.  
  3866. commentsbar_ff_tool.SetPropertyById = commentsbar_ff_set_property;
  3867. commentsbar_ff_tool.SetPropertyByID = commentsbar_ff_set_property;
  3868.  
  3869.  
  3870. function commentsbar_ff_call_highlight()
  3871. {
  3872.     commentsbar_ff_Highlight();
  3873. }
  3874.  
  3875. commentsbar_ff_tool.call_highlight = commentsbar_ff_call_highlight;
  3876.  
  3877.  
  3878. function commentsbar_ff_call_update()
  3879. {
  3880.     commentsbar_ff_update();
  3881. }
  3882. commentsbar_ff_tool.Update = commentsbar_ff_call_update;
  3883.  
  3884.  
  3885. function commentsbar_ff_get_var(sVar)
  3886. {
  3887.     return commentsbar_ff_macro_substitution(sVar);
  3888. }
  3889.  
  3890. commentsbar_ff_tool.getvar = commentsbar_ff_get_var;
  3891.  
  3892. function commentsbar_ff_get_window()
  3893. {
  3894.     var wind = window;
  3895.     return wind;
  3896. }
  3897.  
  3898. commentsbar_ff_tool.getWindow = commentsbar_ff_get_window;
  3899.  
  3900. /////////////////////////////////////////////////////////////////////////////
  3901.  
  3902. function commentsbar_ff_utf8(wide) {
  3903.     var c, s;
  3904.     var enc = "";
  3905.     var i = 0;
  3906.     while (i < wide.length) {
  3907.         c = wide.charCodeAt(i++);
  3908.         // handle UTF-16 surrogates
  3909.         if (c >= 0xDC00 && c < 0xE000) continue;
  3910.         if (c >= 0xD800 && c < 0xDC00) {
  3911.             if (i >= wide.length) continue;
  3912.             s = wide.charCodeAt(i++);
  3913.             if (s < 0xDC00 || c >= 0xDE00) continue;
  3914.             c = ((c - 0xD800) << 10) + (s - 0xDC00) + 0x10000;
  3915.         }
  3916.         // output value
  3917.         if (c < 0x80) enc += String.fromCharCode(c);
  3918.         else if (c < 0x800) enc += String.fromCharCode(0xC0 + (c >> 6), 0x80 + (c & 0x3F));
  3919.         else if (c < 0x10000) enc += String.fromCharCode(0xE0 + (c >> 12), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
  3920.         else enc += String.fromCharCode(0xF0 + (c >> 18), 0x80 + (c >> 12 & 0x3F), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
  3921.     }
  3922.     return enc;
  3923. }
  3924.  
  3925. function commentsbar_ff_toHex(n) {
  3926.     var hexchars = "0123456789ABCDEF";
  3927.     return hexchars.charAt(n >> 4) + hexchars.charAt(n & 0xF);
  3928. }
  3929.  
  3930. function commentsbar_ff_encodeURIComponentNew(s) {
  3931.     var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
  3932.     var s = commentsbar_ff_utf8(s);
  3933.     var c;
  3934.     var enc = "";
  3935.     for (var i = 0; i < s.length; i++) {
  3936.         if (okURIchars.indexOf(s.charAt(i)) == -1)
  3937.             enc += "%" + commentsbar_ff_toHex(s.charCodeAt(i));
  3938.         else
  3939.             enc += s.charAt(i);
  3940.     }
  3941.     return enc;
  3942. }
  3943.  
  3944. function commentsbar_ff_utf8_encode(str)
  3945. {
  3946.     if (str == "") return str;
  3947.     var encodedField = "";
  3948.     var s = str;
  3949.     if (typeof encodeURIComponent == "function")
  3950.     {
  3951.         // Use JavaScript built-in function
  3952.         // IE 5.5+ and Netscape 6+ and Mozilla
  3953.         encodedField = encodeURIComponent(s);
  3954.     }
  3955.     else
  3956.     {
  3957.         // Need to mimic the JavaScript version
  3958.         // Netscape 4 and IE 4 and IE 5.0
  3959.         encodedField = commentsbar_ff_encodeURIComponentNew(s);
  3960.     }
  3961.     return encodedField;
  3962. }
  3963. ////////////////////////////////////////////////////////////
  3964. function commentsbar_ff_getMeta(s)
  3965. {
  3966.     var re1 = new RegExp("<\\s*meta[^<]*name=\"(keywords|description)\"[^<]*>", "gi");
  3967.     var re2 = new RegExp("(content\\s*=\\s*\"[^\"]*\")|(content\\s*=\\s*\'[^\']*\')", "gi");
  3968.     var re3 = new RegExp("(content)|(description)|(\\s*=)|(\\s*[\"\'])", "gi");
  3969.     var ma = s.match(re1);
  3970.     var ms = '';
  3971.     if (ma)
  3972.     {
  3973.         for (var i = 0; i < ma.length; i++)
  3974.         {
  3975.             if (i > 0)
  3976.                 ms += " ";
  3977.             var ts = ma[i].match(re2);
  3978.             if (ts)
  3979.             {
  3980.                 for (var j = 0; j < ma.length; j++)
  3981.                 {
  3982.                     if (j > 0)
  3983.                         ms += " ";
  3984.                     if (ts[j] != undefined)
  3985.                         ms += ts[j].replace(re3, "");
  3986.                 }
  3987.             }
  3988.         }
  3989.     }
  3990.     return ms;
  3991. }
  3992.  
  3993. function commentsbar_ff_getHTMLSelection(s)
  3994. {
  3995.     var q = '';
  3996.     var cnt = s.rangeCount;
  3997.     for (var i = 0; i < cnt; i++)
  3998.     {
  3999.         var nodes = s.getRangeAt(i).cloneContents().childNodes;
  4000.         for (var j = 0; j < nodes.length; j++)
  4001.         {
  4002.             if (typeof(nodes[j].innerHTML) == "undefined")
  4003.                 q += nodes[j].nodeValue;
  4004.             else
  4005.                 q += nodes[j].innerHTML;
  4006.  
  4007.         }
  4008.     }
  4009.     return q;
  4010. }
  4011.  
  4012. function commentsbar_ff_getClipboard()
  4013. {
  4014.     var data = "";
  4015.  
  4016.     var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].getService();
  4017.     if (clipboard) clipboard = clipboard.QueryInterface(Components.interfaces.nsIClipboard);
  4018.  
  4019.     var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance();
  4020.     if (trans)
  4021.         trans = trans.QueryInterface(Components.interfaces.nsITransferable);
  4022.  
  4023.     if (trans && clipboard)
  4024.     {
  4025.         trans.addDataFlavor("text/plain    ");
  4026.         trans.addDataFlavor("text/unicode");
  4027.         clipboard.getData(trans, clipboard.kGlobalClipboard);
  4028.     }
  4029.  
  4030.     var dataObj = new Object();
  4031.     var bestFlavor = new Object();
  4032.     var len = new Object();
  4033.     trans.getAnyTransferData(bestFlavor, dataObj, len);
  4034.     if (bestFlavor.value == "text/plain" || bestFlavor.value == "text/unicode")
  4035.     {
  4036.         if (dataObj)
  4037.             dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
  4038.         if (dataObj)
  4039.             data = dataObj.data;
  4040.     }
  4041.     return data;
  4042. }
  4043.  
  4044.  
  4045.  
  4046.  
  4047.  
  4048. function macro(name, ptr) {
  4049.     this.name = name;
  4050.     this.ptr = ptr;
  4051. }
  4052.  
  4053. var commentsbar_ff_macroes = new Array();
  4054. commentsbar_ff_macroes.push(new macro('%url', 'commentsbar_ff_utf8_encode(window._content.document.location)'));
  4055. commentsbar_ff_macroes.push(new macro('%plain_url', 'window._content.document.location'));
  4056. commentsbar_ff_macroes.push(new macro('%toolbar_id', 'commentsbar_ff_rotool.guid'));
  4057. commentsbar_ff_macroes.push(new macro('%toolbar_version', 'commentsbar_ff_rotool.ver'));
  4058. commentsbar_ff_macroes.push(new macro('%currentlayout', 'commentsbar_ff_tool.Layout'));
  4059. commentsbar_ff_macroes.push(new macro('%domain', 'commentsbar_ff_utf8_encode(window._content.document.domain)'));
  4060. commentsbar_ff_macroes.push(new macro('%plain_domain', 'window._content.document.domain'));
  4061. commentsbar_ff_macroes.push(new macro('%title', 'commentsbar_ff_utf8_encode(window._content.document.title)'));
  4062. commentsbar_ff_macroes.push(new macro('%plain_title', 'window._content.document.title'));
  4063. commentsbar_ff_macroes.push(new macro('%user_name', 'commentsbar_ff_tool.userName'));
  4064. commentsbar_ff_macroes.push(new macro('%user_pass', 'commentsbar_ff_tool.userPasswd'));
  4065. commentsbar_ff_macroes.push(new macro('%user_id', 'commentsbar_ff_tool.userid'));
  4066. commentsbar_ff_macroes.push(new macro('%promoCode', 'commentsbar_ff_tool.promoCode'));
  4067. commentsbar_ff_macroes.push(new macro('%meta', 'commentsbar_ff_utf8_encode(commentsbar_ff_getMeta(window._content.document.documentElement.innerHTML))'));
  4068. commentsbar_ff_macroes.push(new macro('%plain_meta', 'commentsbar_ff_getMeta(window._content.document.documentElement.innerHTML)'));
  4069. commentsbar_ff_macroes.push(new macro('%selection', 'window._content.getSelection()'));
  4070. commentsbar_ff_macroes.push(new macro('%htmlselection', 'commentsbar_ff_getHTMLSelection(window._content.getSelection())'));
  4071. commentsbar_ff_macroes.push(new macro('%encoding', 'window._content.document.characterSet'));
  4072. commentsbar_ff_macroes.push(new macro('%clipboard', 'commentsbar_ff_getClipboard()'));
  4073. commentsbar_ff_macroes.push(new macro('%Var1', 'commentsbar_ff_tool.Var[1]'));
  4074. commentsbar_ff_macroes.push(new macro('%Var2', 'commentsbar_ff_tool.Var[2]'));
  4075. commentsbar_ff_macroes.push(new macro('%Var3', 'commentsbar_ff_tool.Var[3]'));
  4076. commentsbar_ff_macroes.push(new macro('%Var4', 'commentsbar_ff_tool.Var[4]'));
  4077. commentsbar_ff_macroes.push(new macro('%Var5', 'commentsbar_ff_tool.Var[5]'));
  4078. commentsbar_ff_macroes.push(new macro('%Var6', 'commentsbar_ff_tool.Var[6]'));
  4079. commentsbar_ff_macroes.push(new macro('%Var7', 'commentsbar_ff_tool.Var[7]'));
  4080. commentsbar_ff_macroes.push(new macro('%Var8', 'commentsbar_ff_tool.Var[8]'));
  4081. commentsbar_ff_macroes.push(new macro('%Var9', 'commentsbar_ff_tool.Var[9]'));
  4082. commentsbar_ff_macroes.push(new macro('%Var10', 'commentsbar_ff_tool.Var[10]'));
  4083. commentsbar_ff_macroes.push(new macro('%SVar1', 'commentsbar_ff_tool.SVar[1]'));
  4084. commentsbar_ff_macroes.push(new macro('%SVar2', 'commentsbar_ff_tool.SVar[2]'));
  4085. commentsbar_ff_macroes.push(new macro('%SVar3', 'commentsbar_ff_tool.SVar[3]'));
  4086. commentsbar_ff_macroes.push(new macro('%SVar4', 'commentsbar_ff_tool.SVar[4]'));
  4087. commentsbar_ff_macroes.push(new macro('%SVar5', 'commentsbar_ff_tool.SVar[5]'));
  4088. commentsbar_ff_macroes.push(new macro('%SVar6', 'commentsbar_ff_tool.SVar[6]'));
  4089. commentsbar_ff_macroes.push(new macro('%SVar7', 'commentsbar_ff_tool.SVar[7]'));
  4090. commentsbar_ff_macroes.push(new macro('%SVar8', 'commentsbar_ff_tool.SVar[8]'));
  4091. commentsbar_ff_macroes.push(new macro('%SVar9', 'commentsbar_ff_tool.SVar[9]'));
  4092. commentsbar_ff_macroes.push(new macro('%SVar10', 'commentsbar_ff_tool.SVar[10]'));
  4093. commentsbar_ff_macroes.push(new macro('%AffiliateParam', 'commentsbar_ff_tool.AffiliateID'));
  4094. commentsbar_ff_macroes.push(new macro('%random', 'Math.round(Math.random()*32768)'));
  4095.  
  4096. function commentsbar_ff_macro_substitution(s, encoding, post)
  4097. {
  4098.     try {
  4099.         //    Replace names of compo, edit, and password
  4100.         var index = 0;
  4101.         var start,end,replace_str,item_id,item;
  4102.         var enc_charset = commentsbar_ff_get_encoding_name(encoding);
  4103.         const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
  4104.                 .getService(Components.interfaces.nsITextToSubURI);
  4105.         //        s=s.split("(%").join("%");
  4106.  
  4107.         while (s.indexOf("%", index) != -1)
  4108.         {
  4109.             start = s.indexOf("%", index);
  4110.             end = s.indexOf("&", start);
  4111.  
  4112.             if (end == -1 || (s.indexOf("+", start) != -1 && s.indexOf("+", start) < end)) end = s.indexOf("+", start);
  4113.             if (end == -1 || (s.indexOf('\"', start) != -1 && s.indexOf('\"', start) < end)) end = s.indexOf('\"', start);
  4114.             if (end == -1 || (s.indexOf(")", start) != -1 && s.indexOf(")", start) < end)) end = s.indexOf(")", start);
  4115.             if (end == -1 || (s.indexOf("/", start) != -1 && s.indexOf("/", start) < end)) end = s.indexOf("/", start);
  4116.             if (end == -1 || (s.indexOf("/", start) != -1 && s.indexOf("/", start) < end)) end = s.indexOf(".", start);
  4117.             if (end == -1) end = s.length;
  4118.             var end2 = s.indexOf("%", start + 1);
  4119.             if (end2 != -1) if (end2 < end) end = end2;
  4120.             end2 = s.indexOf(" ", start + 1);
  4121.             if (end2 != -1) if (end2 < end) end = end2;
  4122.             index = end;
  4123.  
  4124.             replace_str = s.substring(start, end);
  4125.             item_id = s.substring(start + 1, end);
  4126.             //    item_id=item_id.split(")").join("");
  4127.             item = document.getElementById(item_id);
  4128.  
  4129.             var tb = document.getElementById('commentsbar_ff-toolbar');
  4130.  
  4131.             var radios = tb.getElementsByTagName("radio");
  4132.             for (var i = 0; i < radios.length; i++)
  4133.             {
  4134.                 try {
  4135.                     if (radios[i].getAttribute('group') == item_id)
  4136.                         if (radios[i].getAttribute('selected') == 'true')
  4137.                         {
  4138.                             //val=radios[i].getAttribute('label');
  4139.                             val = radios[i].getAttribute('name');
  4140.                             s = s.split(replace_str).join(val);
  4141.                             if (val.length != replace_str.length) index = start + val.length;
  4142.                         }
  4143.                 } catch(e) {
  4144.                 }
  4145.             }
  4146.  
  4147.  
  4148.             var checks = tb.getElementsByTagName("checkbox");
  4149.             for (var i = 0; i < checks.length; i++)
  4150.             {
  4151.                 try {
  4152.                     if (checks[i].getAttribute('name') == item_id)
  4153.                     {
  4154.                         val = checks[i].getAttribute('checked');
  4155.                         if (checks[i].getAttribute('checked') == 'true') val = '1'
  4156.                         else val = '0'
  4157.                         s = s.split(replace_str).join(val);
  4158.                         if (val.length != replace_str.length) index = start + val.length;
  4159.                     }
  4160.                 } catch(e) {
  4161.                 }
  4162.             }
  4163.  
  4164.  
  4165.             if (item != null)
  4166.             {
  4167.                 var val;
  4168.                 val = item.value.toString();
  4169.                 var text1 = "";//item.getAttribute('ptext');
  4170.                 var text2 = item.getAttribute('text');
  4171.                 if (text1 != "undefined" && text1 != "" && text1 == val) val = "";
  4172.                 if (text2 != "undefined" && text2 != "" && text2 == val) val = "";
  4173.  
  4174.         var val2=commentsbar_ff_macro_substitution(val, encoding, 0);
  4175.         if (val2!=val) post=1;        
  4176.         val=val2;
  4177.  
  4178.                 if (val != "")
  4179.                 {
  4180.                     if (post != 1) val = textToSubURI.ConvertAndEscape(enc_charset, item.value.toString());
  4181.                 }
  4182.                 //            var val = escape(item.value.toString());
  4183.  
  4184.                 if (item.getAttribute('editable') == 'false')
  4185.                 {
  4186.                     var tb = document.getElementById('commentsbar_ff-toolbar');
  4187.                     var combos = tb.getElementsByTagName("menuitem");
  4188.                     for (var i = 0; i < combos.length; i++)
  4189.                     {
  4190.                         if (combos[i].value != null && combos[i].value != "undefined" && combos[i].value != "")
  4191.                         {
  4192.                             if (item.value.toString() == combos[i].label.toString()) val = combos[i].value.toString();
  4193.                         }
  4194.                     }
  4195.                 }
  4196.  
  4197.                 s = s.split(replace_str).join(val);
  4198.                 if (val.length != replace_str.length)
  4199.                     index = start + val.length;
  4200.             }
  4201.         }
  4202.         // variables substitution
  4203.         for (var i = 0; i < commentsbar_ff_macroes.length; i++)
  4204.         {
  4205.             if (s.indexOf(commentsbar_ff_macroes[i].name) != -1)
  4206.                 s = s.split(commentsbar_ff_macroes[i].name).join(eval(commentsbar_ff_macroes[i].ptr));
  4207.         }
  4208.         return s;
  4209.     } catch(e) {
  4210.         if (debugmode) cbLog(e);
  4211.     }
  4212. }
  4213.  
  4214. function commentsbar_ff_get_encoding_name(num)
  4215. {
  4216.     try {
  4217.         var encodings = new Array();
  4218.         encodings['65001'] = 'UTF-8';
  4219.         encodings['28591'] = 'ISO-8859-1';
  4220.         encodings['874'] = 'ISO-8859-15';
  4221.         encodings['1256'] = 'Windows-1256';
  4222.         encodings['1257'] = 'Windows-1257';
  4223.         encodings['28592'] = 'ISO-8859-2';
  4224.         encodings['1250'] = 'Windows-1250';
  4225.         encodings['852'] = 'IBM-852';
  4226.         encodings['51936'] = 'GBK';
  4227.         encodings['936'] = 'GB2312';
  4228.         encodings['52936'] = 'HZ';
  4229.         encodings['10008'] = 'ISO-2022-CN';
  4230.         encodings['950'] = 'Big5';
  4231.         //    encodings['20000']='';" caption="[[Chinese Traditional (CNS)]]"/>
  4232.         //    encodings['20002']='';" caption="[[Chinese Traditional (Eten)]]"/>
  4233.         //    encodings['10002']='';" caption="[[Chinese Traditional (Mac)]]"/>
  4234.         encodings['1251'] = 'Windows-1251';
  4235.         encodings['20866'] = 'KOI8-R';
  4236.         encodings['866'] = 'CP-866';
  4237.         encodings['1255'] = 'Windows-1255';
  4238.         encodings['1253'] = 'Windows-1253';
  4239.         encodings['51932'] = 'EUC-JP';
  4240.         encodings['932'] = 'Shift_JIS';
  4241.         encodings['50220'] = 'ISO-2022-JP';
  4242.         //    encodings['50222']='';" caption="[[Japanese (JIS-Allow 1 byte Kana - SO/SI)]]"/>
  4243.         //    encodings['50221']='';" caption="[[Japanese (JIS-Allow 1 byte Kana)]]"/>
  4244.         //    encodings['50930']='';" caption="[[Japanese (Katakana, Extended)]]"/>
  4245.         //    encodings['10001']='';" caption="[[Japanese (Mac)]]"/>
  4246.         encodings['949'] = 'EUC-KR';
  4247.         encodings['874'] = 'Windows-874';
  4248.         encodings['1254'] = 'Windows-1254';
  4249.         encodings['1258'] = 'Windows-1258';
  4250.         encodings['1252'] = 'Windows-1252';
  4251.  
  4252.         if (encodings[num])
  4253.             return encodings[num];
  4254.         else
  4255.             return 'UTF-8';
  4256.  
  4257.     } catch(e) {
  4258.         if (debugmode) cbLog(e);
  4259.     }
  4260. }
  4261.  
  4262. function commentsbar_ff_macro_substitution_utf8(s)
  4263. {
  4264.     try {
  4265.         //    Replace names of compo, edit, and password
  4266.         var index = 0;
  4267.         var start,end,replace_str,item_id,item;
  4268.         while (s.indexOf("%", index) != -1)
  4269.         {
  4270.             start = s.indexOf("%", index);
  4271.             end = s.indexOf("&", start);
  4272.             if (end == -1) end = s.length;
  4273.             var end2 = s.indexOf("%", start + 1);
  4274.             if (end2 != -1) if (end2 < end) end = end2;
  4275.             end2 = s.indexOf(" ", start + 1);
  4276.             if (end2 != -1) if (end2 < end) end = end2;
  4277.             index = end;
  4278.  
  4279.             replace_str = s.substring(start, end);
  4280.             item_id = s.substring(start + 1, end);
  4281.             item = document.getElementById(item_id);
  4282.  
  4283.             var radios = document.getElementsByTagName("radio");
  4284.             for (var i = 0; i < radios.length; i++)
  4285.             {
  4286.                 try {
  4287.                     if (radios[i].getAttribute('group') == item_id)
  4288.                         if (radios[i].getAttribute('selected') == 'true')
  4289.                         {
  4290.                             //val=radios[i].getAttribute('label');
  4291.                             val = radios[i].getAttribute('id');
  4292.                             s = s.split(replace_str).join(val);
  4293.                             if (val.length != replace_str.length) index = start + val.length;
  4294.                         }
  4295.                 } catch(e) {
  4296.                 }
  4297.             }
  4298.  
  4299.  
  4300.             var checks = document.getElementsByTagName("checkbox");
  4301.             for (var i = 0; i < checks.length; i++)
  4302.             {
  4303.                 try {
  4304.                     if (checks[i].getAttribute('name') == item_id)
  4305.                     {
  4306.                         val = checks[i].getAttribute('checked');
  4307.                         if (checks[i].getAttribute('checked') == 'true') val = '1'
  4308.                         else val = '0'
  4309.                         s = s.split(replace_str).join(val);
  4310.                         if (val.length != replace_str.length) index = start + val.length;
  4311.                     }
  4312.                 } catch(e) {
  4313.                 }
  4314.             }
  4315.  
  4316.  
  4317.             if (item != null)
  4318.             {
  4319.                 var val = item.value.toString();
  4320.  
  4321.                 if (item.getAttribute('editable') == 'false')
  4322.                 {
  4323.                     var combos = document.getElementsByTagName("menuitem");
  4324.                     for (var i = 0; i < combos.length; i++)
  4325.                     {
  4326.                         if (combos[i].value != null && combos[i].value != "undefined" && combos[i].value != "")
  4327.                         {
  4328.                             if (item.value.toString() == combos[i].label.toString()) val = combos[i].value.toString();
  4329.                         }
  4330.                     }
  4331.                 }
  4332.  
  4333.  
  4334.                 var enc = escape(val);
  4335.                 if (enc.indexOf("%u") != -1)
  4336.                 {
  4337.                     enc = commentsbar_ff_utf8_encode(val);
  4338.                     //                val = enc;
  4339.                 }
  4340.                 val = enc;
  4341.                 s = s.split(replace_str).join(val);
  4342.             }
  4343.         }
  4344.         // variables substitution
  4345.         for (var i = 0; i < commentsbar_ff_macroes.length; i++)
  4346.         {
  4347.             if (s.indexOf(commentsbar_ff_macroes[i].name) != -1)
  4348.                 s = s.split(commentsbar_ff_macroes[i].name).join(eval(commentsbar_ff_macroes[i].ptr));
  4349.         }
  4350.         return s;
  4351.     } catch(e) {
  4352.         if (debugmode) cbLog(e);
  4353.     }
  4354. }
  4355.  
  4356.  
  4357. //function commentsbar_ff_FindInPage (str)
  4358. /*
  4359. {
  4360.     var found = false;
  4361.     var focusedWindow = document.commandDispatcher.focusedWindow;
  4362.     if (!focusedWindow || focusedWindow == window) focusedWindow = window._content;
  4363.     var findInst = getBrowser().webBrowserFind;
  4364.     var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  4365.     findInFrames.rootSearchFrame = window._content;
  4366.     findInFrames.currentSearchFrame = focusedWindow;
  4367.     // setup the find instance
  4368.     findInst.searchString  = str;
  4369.     // we hardcode the search options here with what seems to make most sense
  4370.     findInst.searchFrames  = true;
  4371.     findInst.matchCase     = false;
  4372.     findInst.wrapFind      = true;
  4373.     findInst.entireWord    = false;
  4374.     findInst.findBackwards = false;
  4375.     // search
  4376.     found = findInst.findNext();
  4377. }
  4378. */
  4379. function commentsbar_ff_FindInPage(text) {
  4380.  
  4381.     var version2 = typeof gFindBar != "undefined";
  4382.     if (getBrowser().findString == text) {
  4383.         version2 ? gFindBar.findNext() : findNext()
  4384.     }
  4385.     else {
  4386.         version2 ? gFindBar.find(text) : find(text);
  4387.     }
  4388. }
  4389.  
  4390.  
  4391. function commentsbar_ff_refresh_wordfind()
  4392. {
  4393.     try {
  4394.         commentsbar_ff_combochange();
  4395.         var terms = commentsbar_ff_get_input_terms();
  4396.         var box = document.getElementById('commentsbar_ff_wordfindbox');
  4397.         var i, btn;
  4398.         if (!box) return;
  4399.         for (i = box.childNodes.length; i > 0; i--)
  4400.         {
  4401.             box.removeChild(box.childNodes[0]);
  4402.         }
  4403.  
  4404.         if (commentsbar_ff_get_opt('showfindbuttons') == 1)
  4405.         {
  4406.             for (var i = 0; i < terms.length; i++)
  4407.             {
  4408.                 btn = document.createElement('toolbarbutton');
  4409.                 var msgbox = document.getElementById('message_FindWord');
  4410.                 if (msgbox && msgbox.getAttribute("value") != '')
  4411.                 {
  4412.                     var val = msgbox.getAttribute("value").split('%currentword').join(terms[i]);
  4413.                     btn.setAttribute('tooltiptext', val);
  4414.                 }
  4415.  
  4416.                 btn.setAttribute('label', terms[i]);
  4417.                 btn.setAttribute('class', 'commentsbar_ff_wordfindbutton');
  4418.                 btn.setAttribute('onclick', 'commentsbar_ff_FindInPage("' + terms[i] + '");');
  4419.                 box.appendChild(btn);
  4420.             }
  4421.         }
  4422.     } catch(e) {
  4423.         if (debugmode) cbLog(e);
  4424.     }
  4425. }
  4426.  
  4427.  
  4428. function commentsbar_ff_get_opt(opt)
  4429. {
  4430.     try {
  4431.         if (!opt) return;
  4432.         var settings_box = document.getElementById('settings');
  4433.         if (settings_box)
  4434.             return settings_box.getAttribute(opt);
  4435.         return 0;
  4436.     } catch(e) {
  4437.         if (debugmode) cbLog(e);
  4438.     }
  4439. }
  4440.  
  4441. function commentsbar_ff_set_opt(opt, val)
  4442. {
  4443.     try {
  4444.         if (!opt) return;
  4445.         var settings_box = document.getElementById('settings');
  4446.         if (settings_box)
  4447.             settings_box.setAttribute(opt, val);
  4448.  
  4449.     } catch(e) {
  4450.         if (debugmode) cbLog(e);
  4451.     }
  4452. }
  4453.  
  4454. function commentsbar_ff_menu_clearStyle(menu)
  4455. {
  4456.     try {
  4457.         if (menu.tagName != 'menu' && menu.tagName != 'menupopup')
  4458.             return;
  4459.         for (var i = 0; i < menu.childNodes.length; i++)
  4460.         {
  4461.             var item = menu.childNodes[i];
  4462.             if (item.tagName != 'menu' && item.tagName != 'menuitem' && item.tagName != 'menupopup')
  4463.                 continue;
  4464.             if (item.tagName == 'menu' || item.tagName == 'menupopup')
  4465.                 commentsbar_ff_menu_clearStyle(item);
  4466.             if ((item.tagName == 'menu' || item.tagName == 'menuitem') && item.hasAttribute('menu_style_out'))
  4467.                 item.setAttribute('style', item.getAttribute('menu_style_out'));
  4468.         }
  4469.     } catch(e) {
  4470.         if (debugmode) cbLog(e);
  4471.     }
  4472. }
  4473.  
  4474. function commentsbar_ff_show_split_menu(tb_button)
  4475. {
  4476.     try {
  4477.         var b = document.getElementById(tb_button);
  4478.         var menus = b.getElementsByTagName('menupopup');
  4479.         var m = menus.item(0);
  4480.         commentsbar_ff_menu_clearStyle(m);
  4481.         m.showPopup(b, -1, -1, "popup", "bottomleft", "topleft");
  4482.     } catch(e) {
  4483.         if (debugmode) cbLog(e);
  4484.     }
  4485. }
  4486.  
  4487. function parse_all_banner_links()
  4488. {
  4489.     var alinks = this.contentDocument.getElementsByTagName("A");
  4490.     var ahref;
  4491.     var tmp;
  4492.     var h;
  4493.     var target_atr = '';
  4494.     var href_old = this.getAttribute('src');
  4495.     for (i = 0; i < alinks.length; i++)
  4496.     {
  4497.         h = alinks.item(i);
  4498.         if (h != null)
  4499.         {
  4500.             if (h.getAttribute('target'))
  4501.             {
  4502.                 target_atr = h.getAttribute('target');
  4503.                 h.setAttribute('target', '');
  4504.             }
  4505.             ahref = h.getAttribute('href');
  4506.             if (!ahref)
  4507.                 continue;
  4508.             if (ahref.lastIndexOf('javascript') != -1) continue;
  4509.             tmp = ahref.lastIndexOf('#inbanner');
  4510.             if (tmp == -1)
  4511.             {
  4512.                 if (target_atr == '_blank')
  4513.                     h.setAttribute('href', 'javascript:window.open(\'' + ahref + '\');document.location=\'' + href_old + '\'');
  4514.                 else
  4515.                     h.setAttribute('href', 'javascript:window._content.location=\'' + ahref + '\';document.location=\'' + href_old + '\'');
  4516.             }
  4517.             else
  4518.             {
  4519.                 var str_tmp = ahref.substring(0, tmp);
  4520.                 h.setAttribute('href', 'javascript:document.location=\'' + str_tmp + '\'');
  4521.             }
  4522.         }
  4523.     }
  4524. }
  4525.  
  4526. var bubble_req;
  4527. var bubble_cur_proc;
  4528.  
  4529. function commentsbar_ff_OnBannerLoad(e)
  4530. {
  4531.     try {
  4532.         var f = e.currentTarget;
  4533.         if (!f)
  4534.             return;
  4535.         if (f.getAttribute('bannertype') == 'script') return;
  4536.         if (f.contentDocument.defaultView.window.ToolBarInit)
  4537.             f.contentDocument.defaultView.window.ToolBarInit(commentsbar_ff_tool);
  4538.         if (f.contentDocument.defaultView.window.DocumentComplete)
  4539.         {
  4540.             f.contentDocument.defaultView.window.DocumentComplete(commentsbar_ff_tool);
  4541.             refresh_include_xml_type = 'OnDocumentComplete';
  4542.             commentsbar_ff_refresh_layout();
  4543.         }
  4544.     } catch(e) {
  4545.         if (debugmode) cbLog(e);
  4546.     }
  4547. }
  4548.  
  4549. function commentsbar_ff_OnBubbleLoad(e)
  4550. {
  4551.     try {
  4552.         var f = document.getElementById(bubble_cur_proc);
  4553.         if (!f)
  4554.             return;
  4555.         if (f.contentDocument.defaultView.window.ToolBarInit)
  4556.             f.contentDocument.defaultView.window.ToolBarInit(commentsbar_ff_tool);
  4557.         if (f.contentDocument.defaultView.window.DocumentComplete)
  4558.             f.contentDocument.defaultView.window.DocumentComplete(commentsbar_ff_tool);
  4559.     } catch(e) {
  4560.         if (debugmode) cbLog(e);
  4561.     }
  4562. }
  4563.  
  4564. var bubblewindow = 0;
  4565.  
  4566.  
  4567. var localhtml = "";
  4568. function make_bubble(button, mhref, width, height, local, inbanner, usescroll)
  4569. {
  4570.     try {
  4571.         mhref = commentsbar_ff_macro_substitution_utf8(mhref);
  4572.  
  4573.         localhtml = local;
  4574.         var mmm = document.getElementById(button);
  4575.         var m2 = document.getBoxObjectFor(mmm);
  4576.         var xx = m2.x;
  4577.         var height2 = m2.screenY - m2.y - window.screenY;
  4578.         var yy = m2.y + m2.height + height2;
  4579.  
  4580.         mhref = commentsbar_ff_macro_substitution(mhref);
  4581.         commentsbar_ff_pref("bubble_screenx", xx);
  4582.         commentsbar_ff_pref("bubble_screeny", yy);
  4583.         commentsbar_ff_pref("bubble_width", width);
  4584.         commentsbar_ff_pref("bubble_height", height);
  4585.         commentsbar_ff_pref("bubble_type", inbanner);
  4586.         commentsbar_ff_pref("bubble_scroll", usescroll);
  4587.         var mhref2 = mhref;
  4588.         if (mhref.indexOf('http://') == -1 && mhref.indexOf('https://') == -1) mhref2 = "chrome://commentsbar_ff/content/" + mhref;
  4589.         commentsbar_ff_pref("bubble_src", mhref2);
  4590.         if (!local)
  4591.         {
  4592.             if (bubblewindow != 0 && bubblewindow.closed == false) {
  4593.                 bubblewindow.close();
  4594.                 return;
  4595.             }
  4596.             if (closeflag == 1) return;
  4597.             bubblewindow = window.openDialog('chrome://commentsbar_ff/content/bubble.xul', '', 'dependent=yes,titlebar=no');
  4598.             bubblewindow.window.mainwindow = window;
  4599.             bubblewindow.window.tool = commentsbar_ff_tool;
  4600.             window.addEventListener("focus", closebubble, true);
  4601.         }
  4602.         else
  4603.         {
  4604.             bubble_req = new XMLHttpRequest();
  4605.             bubble_req.onreadystatechange = processReqBubble1;
  4606.             bubble_req.open("GET", mhref, true);
  4607.             bubble_req.send(null);
  4608.         }
  4609.     } catch(e) {
  4610.         if (debugmode) cbLog(e);
  4611.     }
  4612. }
  4613.  
  4614. function processReqBubble1()
  4615. {
  4616.     try {
  4617.         if (bubble_req.readyState == 4)
  4618.         {
  4619.             if (bubble_req.responseText != "" && bubble_req.status == 200)
  4620.             {
  4621.                 if (bubblewindow != 0 && bubblewindow.closed == false) {
  4622.                     bubblewindow.close();
  4623.                     return;
  4624.                 }
  4625.                 if (closeflag == 1) return;
  4626.                 bubblewindow = window.openDialog('chrome://commentsbar_ff/content/bubble.xul', '', 'dependent=yes,titlebar=no');
  4627.                 bubblewindow.window.mainwindow = window;
  4628.                 bubblewindow.window.tool = commentsbar_ff_tool;
  4629.                 window.addEventListener("focus", closebubble, true);
  4630.             }
  4631.             else
  4632.             {
  4633.                 var mhref = "chrome://commentsbar_ff/content/" + localhtml;
  4634.                 commentsbar_ff_pref("bubble_src", mhref);
  4635.                 if (bubblewindow != 0 && bubblewindow.closed == false) {
  4636.                     bubblewindow.close();
  4637.                     return;
  4638.                 }
  4639.                 if (closeflag == 1) return;
  4640.                 bubblewindow = window.openDialog('chrome://commentsbar_ff/content/bubble.xul', '', 'dependent=yes,titlebar=no');
  4641.                 bubblewindow.window.mainwindow = window;
  4642.                 bubblewindow.window.tool = commentsbar_ff_tool;
  4643.                 window.addEventListener("focus", closebubble, true);
  4644.             }
  4645.         }
  4646.     } catch(e) {
  4647.         if (debugmode) cbLog(e);
  4648.     }
  4649. }
  4650.  
  4651.  
  4652. var closeflag = 0;
  4653.  
  4654. function closebubble(e)
  4655. {
  4656.     try {
  4657.         if (bubblewindow != 0 && bubblewindow.closed == false) {
  4658.             bubblewindow.close();
  4659.             return;
  4660.         }
  4661.         window.removeEventListener('focus', closebubble, true);
  4662.         closeflag = 1;
  4663.         setTimeout('change_closeflag();', 500);
  4664.         //bubblewindow.removeEventListener("blur",closebubble,true);
  4665.  
  4666.     } catch(e) {
  4667.         if (debugmode) cbLog(e);
  4668.     }
  4669. }
  4670.  
  4671. function change_closeflag()
  4672. {
  4673.     closeflag = 0;
  4674. }
  4675.  
  4676. function close_bubble() {
  4677.     try {
  4678.         if (bubblewindow != 0 && bubblewindow.closed == false) {
  4679.             bubblewindow.close();
  4680.             return;
  4681.         }
  4682.     } catch(e) {/*alert(e);*/
  4683.     }
  4684.     ;
  4685. }
  4686. commentsbar_ff_tool.closebubble = close_bubble;
  4687.  
  4688.  
  4689. function bubble_show(e, tb_button, src, width, height, local) //only one
  4690. {
  4691.     try {
  4692.         var bub = document.getElementById(tb_button + '_bubble');
  4693.  
  4694.         if (bub == null || !bub || bub == 'undefined')
  4695.         {
  4696.             src = commentsbar_ff_macro_substitution_utf8(src);
  4697.  
  4698.             var fr = window.document.createElement("iframe");
  4699.             var m = document.getElementById(tb_button + '_bubble_popup');
  4700.  
  4701.             fr.setAttribute('src', src);
  4702.             fr.setAttribute('height', height);
  4703.             fr.setAttribute('width', width);
  4704.             fr.setAttribute('class', 'if');
  4705.             fr.setAttribute('local', local);
  4706.             fr.setAttribute('id', tb_button + '_bubble');
  4707.             m.addEventListener('load', commentsbar_ff_OnBubbleLoad, true);
  4708.             m.appendChild(fr);
  4709.             fr.focus();
  4710.             window._content.focus();
  4711.             bubble_cur_proc = tb_button + '_bubble';
  4712.             //--------------------------
  4713.             if (!local)
  4714.             {
  4715.                 if (src.indexOf('http') != 0)
  4716.                     src = 'chrome://commentsbar_ff/content/' + src;
  4717.                 var f = document.getElementById(bubble_cur_proc);
  4718.                 f.webNavigation.loadURI(src, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null);
  4719.             }
  4720.             else
  4721.             {
  4722.                 bubble_req = new XMLHttpRequest();
  4723.                 bubble_req.onreadystatechange = processReqBubble;
  4724.                 bubble_req.open("GET", src, true);
  4725.                 bubble_req.send(null);
  4726.             }
  4727.         }
  4728.  
  4729.     } catch(e) {
  4730.         if (debugmode) cbLog(e);
  4731.     }
  4732. }
  4733.  
  4734. function processReqBubble()
  4735. {
  4736.     try {
  4737.         if (bubble_req.readyState == 4)
  4738.         {
  4739.             var f = document.getElementById(bubble_cur_proc);
  4740.             if (!f) return;
  4741.             if (bubble_req.responseText != "" && bubble_req.status == 200)
  4742.                 f.webNavigation.loadURI(f.getAttribute('src'), Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null);
  4743.             else
  4744.                 f.webNavigation.loadURI('chrome://commentsbar_ff/content/' + f.getAttribute('local'), Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null);
  4745.         }
  4746.     } catch(e) {
  4747.         if (debugmode) cbLog(e);
  4748.     }
  4749. }
  4750.  
  4751. function bubble_hide(e, tb_button)
  4752. {
  4753.     try {
  4754.         var bub = document.getElementById(tb_button + '_bubble');
  4755.  
  4756.         if (!(bub == null || !bub || bub == 'undefined'))
  4757.         {
  4758.             var m = document.getElementById(tb_button + '_bubble_popup');
  4759.             m.removeEventListener('load', commentsbar_ff_OnBubbleLoad, true);
  4760.             m.removeChild(bub);
  4761.         }
  4762.  
  4763.     } catch(e) {
  4764.         if (debugmode) cbLog(e);
  4765.     }
  4766. }
  4767.  
  4768. function bubble_click(e, tb_button)
  4769. {
  4770.     //Function is bypassed. Because it crushed firefox with "commentsbar_ff toolbar".
  4771.     //And why need to catch bubble events?
  4772.     //return;
  4773.     try {
  4774.         var target = e.originalTarget;
  4775.  
  4776.         if (target.tagName.toLowerCase() != 'a' && target.parentNode && target.parentNode.tagName)
  4777.         {
  4778.             if (target.parentNode.tagName.toLowerCase() == 'a') target = target.parentNode;
  4779.         }
  4780.         var tag = target.tagName.toLowerCase();
  4781.  
  4782.         switch (tag)
  4783.                 {
  4784.             case 'a':
  4785.                 fr = document.getElementById(tb_button + '_bubble');
  4786.                 href_old = fr.contentDocument.location;
  4787.                 href = target.href;
  4788.  
  4789.                 if (href.lastIndexOf('javascript') != -1) break;
  4790.  
  4791.                 tmp = href.lastIndexOf('#inbanner');
  4792.                 if (tmp == -1)
  4793.                 {
  4794.                     if (target.getAttribute('target') == '_blank')
  4795.                         window.open(href);
  4796.                     else
  4797.                     {
  4798.                         window._content.document.location = href;
  4799.                     }
  4800.                 }
  4801.                 else
  4802.                 {
  4803.                     var str_tmp = href.substring(0, tmp);
  4804.                     fr.contentDocument.location = str_tmp;
  4805.                     e.preventDefault();
  4806.                 }
  4807.                 break
  4808.             default:
  4809.                 e.preventDefault();
  4810.         }
  4811.  
  4812.     } catch(e) {
  4813.         if (debugmode) cbLog(e);
  4814.     }
  4815. }
  4816.  
  4817. function commentsbar_ff_showhide()
  4818. {
  4819.     var tb = document.getElementById('commentsbar_ff-toolbar');
  4820.     var m = document.getElementById('commentsbar_ff_showhide');
  4821.     if (m)
  4822.     {
  4823.         if (tb.getAttribute("collapsed")) {
  4824.             m.setAttribute('checked', true);
  4825.         } else {
  4826.             m.setAttribute('checked', false);
  4827.         }
  4828.     }
  4829.  
  4830.     if (tb.getAttribute("collapsed")) {
  4831.         tb.setAttribute("collapsed", "false");
  4832.     } else {
  4833.         tb.setAttribute("collapsed", "true");
  4834.     }
  4835. }
  4836.  
  4837.  
  4838. function commentsbar_ff_context_search(contmenu)
  4839. {
  4840.     try {
  4841.         var term = "";
  4842.         try {
  4843.             term = contmenu.searchSelected();
  4844.         } catch(k) {
  4845.             term = getBrowserSelection();
  4846.         }
  4847.  
  4848.         var urlbox = document.getElementById('url_contextSearch');
  4849.         var url = urlbox.getAttribute('value');
  4850.         url = url.replace(/\%[^\s&]+/, term);
  4851.  
  4852.         commentsbar_ff_webjump(url, "", "", "");
  4853.     } catch(e) {
  4854.         if (debugmode) cbLog(e);
  4855.     }
  4856. }
  4857.  
  4858.  
  4859. //------------------------------------------------------------------------------
  4860.  
  4861. function commentsbar_ff_update_layout() //reload all include boxes
  4862. {
  4863.     try
  4864.     {
  4865.         all_req_send = 0;
  4866.         var tb = document.getElementById('commentsbar_ff-toolbar');
  4867.         var include = tb.getElementsByTagName("box");
  4868.         if (!include || include == '' || include == 'undefined') return;
  4869.         var cmb_tmp;
  4870.         var i,j = 0;
  4871.  
  4872.         if (requests == null)
  4873.         {
  4874.             requests = new Array();
  4875.             for (var i = 0; i < include.length; i++)
  4876.             {
  4877.                 cmb_tmp = include.item(i);
  4878.                 if (!cmb_tmp.getAttribute('filename')) continue;
  4879.  
  4880.                 requests[j] = new Array();
  4881.                 requests[j].push(cmb_tmp.getAttribute('id'));
  4882.                 requests[j].push('commentsbar_ff-toolbar');
  4883.                 requests[j].push('0');
  4884.                 j++;
  4885.             }
  4886.         }
  4887.  
  4888.         for (var i = cur_req + 1; i < requests.length; i++)
  4889.         {
  4890.             cmb_tmp = document.getElementById(requests[i][0]);
  4891.             if (wait == 1) {
  4892.                 setTimeout('commentsbar_ff_update_layout();', 50);
  4893.                 return;
  4894.             }
  4895.             if (!cmb_tmp || !cmb_tmp.getAttribute('filename')) continue;
  4896.  
  4897.             //        if (requests[i][2]=='0' && !(Number(cmb_tmp.getAttribute('layout')) == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout ==0)))
  4898.  
  4899.             for (var ii = 0; ii < requests.length; ii++)
  4900.             {
  4901.                 var cmb_tmp2 = document.getElementById(requests[ii][0]);
  4902.                 if (!cmb_tmp2 || !cmb_tmp2.getAttribute('filename')) continue;
  4903.                 if (!(Number(cmb_tmp2.getAttribute('layout')) == commentsbar_ff_tool.Layout || (!cmb_tmp2.getAttribute('layout') && commentsbar_ff_tool.Layout == 0)))
  4904.                 {
  4905.                     //remove old childs
  4906.                     var old_box = document.getElementById(requests[ii][0]);
  4907.                     if (old_box)
  4908.                     {
  4909.                         var old_childs = old_box.childNodes;
  4910.                         var len = old_childs.length;
  4911.                         for (var c = 0; c < len; c++)
  4912.                             old_box.removeChild(old_box.childNodes.item(0));
  4913.                         old_box.setAttribute('flex', 0);
  4914.                     }
  4915.                 }
  4916.             }
  4917.  
  4918.             //        if (requests[i][2]=='0' && (cmb_tmp.getAttribute('layout') == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout ==0)))
  4919.             if (requests[i][2] == '0' && (cmb_tmp.getAttribute('layout') == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout == 0)))
  4920.             {
  4921. /*
  4922. var host="";
  4923. try{
  4924. host=window._content.document.location.host;
  4925. }catch(e){host="about:blank"}
  4926. if (cmb_tmp.getAttribute('urltemplate')!="" &&cmb_tmp.getAttribute('urltemplate')!=host) continue; 
  4927. */
  4928.                 cur_req = i;
  4929.                 wait = 1;
  4930.                 //send request one by one for all includes
  4931.                 url = cmb_tmp.getAttribute('filename');
  4932.                 primeurl = url;
  4933.                 //experimental!
  4934.                 url = commentsbar_ff_macro_substitution_utf8(url);
  4935.                 url = commentsbar_ff_macro_substitution_utf8(url);
  4936.                 //!!!
  4937.  
  4938.                 if (url.indexOf('http') == 0)
  4939.                 {
  4940.                     //
  4941.                     var cache_data = commentsbar_ff_LoadLocalFile(primeurl, true);
  4942.  
  4943.                     var cache_date = commentsbar_ff_load_pref("commentsbar_ff.cache." + requests[i][0], "");
  4944.                     var cdate = new Date();
  4945.                     var load_local = false;
  4946.                     if (cache_date)
  4947.                     {
  4948.                         var cache_date_tmp = cache_date.split('/');
  4949.                         var ex_time = (cdate.getMinutes() - cache_date_tmp[0]) + (cdate.getHours() - cache_date_tmp[1]) * 60 + (cdate.getDate() - cache_date_tmp[2]) * 60 * 24 + (cdate.getMonth() - cache_date_tmp[3]) * 60 * 24 * 30 + (cdate.getYear() - cache_date_tmp[4]) * 60 * 24 * 30 * 365;
  4950.  
  4951.                         if (ex_time < Number(cmb_tmp.getAttribute('expire')))
  4952.                             load_local = true;
  4953.                     }
  4954.  
  4955.                     if (cache_data && load_local)
  4956.                         commentsbar_ff_process_cache(cache_data);
  4957.                     else
  4958.                     {
  4959.                         send_request();
  4960.                         var new_date = cdate.getMinutes() + '/' + cdate.getHours() + '/' + cdate.getDate() + '/' + cdate.getMonth() + '/' + cdate.getYear();
  4961.                         commentsbar_ff_pref("commentsbar_ff.cache." + requests[i][0], new_date.toString());
  4962.                     }
  4963.  
  4964.                 }
  4965.                 else
  4966.                     send_local_request();
  4967.             }
  4968.             else if (requests[i][2] != '3')
  4969.             {
  4970.                 requests[i][2] = '1';
  4971.             }
  4972.  
  4973.         }
  4974.         commentsbar_ff_all_req_processed();
  4975.     } catch(e) {
  4976.         if (debugmode) cbLog(e);
  4977.     }
  4978. }
  4979.  
  4980.  
  4981. function commentsbar_ff_all_req_processed()
  4982. {
  4983.     try {
  4984.         if (wait != 0) {
  4985.             setTimeout('commentsbar_ff_all_req_processed();', 1);
  4986.             return;
  4987.         }
  4988.  
  4989.         var ir = 0;
  4990.         for (ir = 0; ir < requests.length; ++ir)
  4991.             if (requests[ir][2] == '0') {
  4992.                 ir = -1;
  4993.                 break;
  4994.             }
  4995.  
  4996.         if (ir != -1)
  4997.         {
  4998.             cur_req = -1;
  4999.             if (nestedXML)
  5000.             {
  5001.                 for (var ir = 0; ir < requests.length; ++ir)
  5002.                     if (requests[ir][2] == '3') requests[ir][2] = '0';
  5003.                 nestedXML = false;
  5004.                 commentsbar_ff_update_layout();
  5005.             }
  5006.             else
  5007.             {
  5008.                 for (var i = 0; i < requests.length; ++i)
  5009.                     requests[i][2] = '0';
  5010.                 commentsbar_ff_on_all_includexml_load();
  5011.             }
  5012.         }
  5013.         else
  5014.         {
  5015.             setTimeout('commentsbar_ff_all_req_processed();', 1);
  5016.             return;
  5017.         }
  5018.  
  5019.     } catch(e) {
  5020.         if (debugmode) cbLog(e);
  5021.     }
  5022. }
  5023.  
  5024.  
  5025. function commentsbar_ff_process_cache(cache_data)
  5026. {
  5027.     try {
  5028.         if (cache_data != "")
  5029.         {
  5030.             var xulString = cache_data.replace(/>[\s\t\n]+</g, "><");
  5031.             //remove spaces
  5032.             xulString = xulString.replace(/\\/g, '\\\\');
  5033.             // for shellex-ecute (\ in command)
  5034.  
  5035.             var parser = new DOMParser();
  5036.             var resultDoc = parser.parseFromString(xulString, "text/xml");
  5037.  
  5038.             var newFragment = commentsbar_ff_processor.transformToFragment(resultDoc, document);
  5039.  
  5040.             var t = document.getElementById(requests[cur_req][1]);
  5041.             var oldbox = document.getElementById(requests[cur_req][0]);
  5042.             if (!oldbox) return;
  5043.             var rid = oldbox.getAttribute('id');
  5044.             var rlayout = oldbox.getAttribute('layout');
  5045.             var rfilename = oldbox.getAttribute('filename');
  5046.             var rsync = oldbox.getAttribute('sync');
  5047.             var rno_cache = oldbox.getAttribute('no_cache');
  5048.             var rurltemplate = oldbox.getAttribute('urltemplate');
  5049.             var rlocal = oldbox.getAttribute('local');
  5050.             var rexpire = oldbox.getAttribute('expire');
  5051.             var rflex = oldbox.getAttribute('flex');
  5052.  
  5053.             var newnode = document.importNode(newFragment, true);
  5054.         commentsbar_ff_hideelements(newnode);
  5055.             t.replaceChild(newnode, oldbox);
  5056.         commentsbar_ff_setevents(t);    
  5057.  
  5058.             var new_box = document.getElementById('layout-box');
  5059.             if (new_box)
  5060.             {
  5061.                 new_box.setAttribute('id', rid);
  5062.                 new_box.setAttribute('layout', rlayout);
  5063.                 new_box.setAttribute('filename', rfilename);
  5064.                 new_box.setAttribute('sync', rsync);
  5065.                 new_box.setAttribute('no_cache', rno_cache);
  5066.                 new_box.setAttribute('urltemplate', rurltemplate);
  5067.                 new_box.setAttribute('local', rlocal);
  5068.                 new_box.setAttribute('expire', rexpire);
  5069.                 new_box.setAttribute('flex', rflex);
  5070.  
  5071.                 //check for nested XMLs
  5072.                 var include = new_box.getElementsByTagName("box");
  5073.                 if (include)
  5074.                 {
  5075.                     var cmb_tmp;
  5076.                     for (i = 0; i < include.length; i++)
  5077.                     {
  5078.                         cmb_tmp = include.item(i);
  5079.                         if (!cmb_tmp.getAttribute('filename')) continue;
  5080.  
  5081.                         var j;
  5082.                         for (j = 0; j < requests.length; j++)
  5083.                             if (requests[j][0] == cmb_tmp.getAttribute('id')) break;
  5084.  
  5085.                         if (j == requests.length)
  5086.                         {
  5087.                             requests[j] = new Array();
  5088.                             requests[j][0] = cmb_tmp.getAttribute('id');
  5089.                             requests[j][1] = rid;
  5090.                             requests[j][2] = '3';
  5091.                             nestedXML = true;
  5092.                         }
  5093.                     }
  5094.                 }
  5095.             }
  5096.             requests[cur_req][2] = '1';
  5097.             commentsbar_ff_on_includexml_load();
  5098.             wait = 0;
  5099.             //next request can be send
  5100.         }
  5101.  
  5102.     } catch(e) {
  5103.         if (debugmode) cbLog(e);
  5104.     }
  5105. }
  5106.  
  5107.  
  5108. function commentsbar_ff_on_includexml_load()
  5109. {
  5110.     try {
  5111.         commentsbar_ff_restore_persisted_attributes();
  5112.         //label is modified here
  5113.         delete sw_cmds;
  5114.         sw_cmds = new Array();
  5115.     } catch(e) {
  5116.         if (debugmode) cbLog(e);
  5117.     }
  5118. }
  5119.  
  5120. function commentsbar_ff_on_all_includexml_load()
  5121. {
  5122.     try {                                        //alert('all xml start');
  5123.         commentsbar_ff_restore_persisted_attributes();
  5124.         //label is modified here
  5125.         // commentsbar_ff_all_combo_update_history();
  5126.  
  5127.     } catch(e) {
  5128.         if (debugmode) cbLog(e);
  5129.     }
  5130. }
  5131.  
  5132.  
  5133. //////////////////////////////////////////////local files
  5134.  
  5135.  
  5136. function commentsbar_ff_SaveLocalFile(buffer, filename, cache)
  5137. {
  5138.     try {
  5139.         var file;
  5140.         if (cache == true)
  5141.         {
  5142.             var cache_file_name = hex_md5(filename);
  5143.             if (buffer.indexOf('img') != -1 || buffer.indexOf('image') != -1 || buffer.indexOf('hot_image') != -1)
  5144.             {
  5145.                 var imgurl = filename.replace(/^(.+\/)[^\/]+$/, "$1");
  5146.                 commentsbar_ff_SaveImagesToCache(buffer, imgurl);
  5147.             }
  5148.             filename = filename.replace(/.+\/(.+)$/, "$1");
  5149.             var cache_path = commentsbar_ff_get_cache_path();
  5150.             file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  5151.             file.initWithPath(cache_path);
  5152.             file.append(cache_file_name);
  5153.         }
  5154.         else
  5155.         {
  5156.             file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  5157.             file.initWithPath(filename);
  5158.         }
  5159.  
  5160.         try {
  5161.             file.remove(false);
  5162.         } catch(r) {
  5163.         }
  5164.  
  5165.         //save
  5166.         file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0664);
  5167.         var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
  5168.                 .createInstance(Components.interfaces.nsIFileOutputStream);
  5169.         foStream.init(file, 0x02 | 0x08 | 0x20, 0664, 0);
  5170.         // write, create, truncate
  5171.         foStream.write(buffer, buffer.length);
  5172.         foStream.close();
  5173.  
  5174.     } catch(e) {
  5175.         if (debugmode) cbLog(e);
  5176.     }
  5177. }
  5178.  
  5179. function commentsbar_ff_SaveImagesToCache(buffer, imgurl)
  5180. {
  5181.     try {
  5182.         if (buffer == "" || buffer == null || buffer == "undefined") return;
  5183.         var xmltext = buffer;
  5184.         var pos = 0;
  5185.         var start = 0;
  5186.         var end;
  5187.         var img;
  5188.         var ioService;
  5189.         var channel;
  5190.         var listener;
  5191.         while (pos < xmltext.length && xmltext.indexOf(' img', pos) != -1)
  5192.         {
  5193.             start = xmltext.indexOf(' img', pos) + 6;
  5194.             end = xmltext.indexOf('"', start);
  5195.             end2 = xmltext.indexOf("'", start);
  5196.             if (end == -1) end = end2;
  5197.             if (end2 < end) end = end2;
  5198.             if (end == -1) break;
  5199.             pos = end + 1;
  5200.             if (start == end) continue;
  5201.             img = xmltext.substring(start, end);
  5202.             if (!img || img.indexOf('http') != 0) continue;
  5203.             ioService = Components.classes["@mozilla.org/network/io-service;1"]
  5204.                     .getService(Components.interfaces.nsIIOService);
  5205.  
  5206.             channel = ioService.newChannel(img, null, null);
  5207.             listener = new imgLoadListener(channel, img);
  5208.             channel.notificationCallbacks = listener;
  5209.             channel.asyncOpen(listener, null);
  5210.         }
  5211.  
  5212.         pos = 0;
  5213.         while (pos < xmltext.length && xmltext.indexOf(' image', pos) != -1)
  5214.         {
  5215.             start = xmltext.indexOf(' image', pos) + 8;
  5216.             end = xmltext.indexOf('"', start);
  5217.             end2 = xmltext.indexOf("'", start);
  5218.             if (end == -1) end = end2;
  5219.             if (end2 < end) end = end2;
  5220.             if (end == -1) break;
  5221.             pos = end + 1;
  5222.             if (start == end) continue;
  5223.             img = xmltext.substring(start, end);
  5224.             if (!img || img.indexOf('http') != 0) continue;
  5225.             ioService = Components.classes["@mozilla.org/network/io-service;1"]
  5226.                     .getService(Components.interfaces.nsIIOService);
  5227.  
  5228.             channel = ioService.newChannel(img, null, null);
  5229.             listener = new imgLoadListener(channel, img);
  5230.             channel.notificationCallbacks = listener;
  5231.             channel.asyncOpen(listener, null);
  5232.         }
  5233.  
  5234.         pos = 0;
  5235.         while (pos < xmltext.length && xmltext.indexOf(' hot_image', pos) != -1)
  5236.         {
  5237.             start = xmltext.indexOf(' hot_image', pos) + 12;
  5238.             end = xmltext.indexOf('"', start);
  5239.             end2 = xmltext.indexOf("'", start);
  5240.             if (end == -1) end = end2;
  5241.             if (end2 < end) end = end2;
  5242.             if (end == -1) break;
  5243.             pos = end + 1;
  5244.             if (start == end) continue;
  5245.             img = xmltext.substring(start, end);
  5246.             if (!img || img.indexOf('http') != 0) continue;
  5247.             //        if (!img || img.toLowerCase().indexOf('.bmp')==-1) continue;
  5248.             //        img=img.replace(/\.bmp$/i,'.png');
  5249.             ioService = Components.classes["@mozilla.org/network/io-service;1"]
  5250.                     .getService(Components.interfaces.nsIIOService);
  5251.  
  5252.             channel = ioService.newChannel(img, null, null);
  5253.             listener = new imgLoadListener(channel, img);
  5254.             channel.notificationCallbacks = listener;
  5255.             channel.asyncOpen(listener, null);
  5256.         }
  5257.  
  5258.     } catch(e) {
  5259.         if (debugmode) cbLog(e);
  5260.     }
  5261. }
  5262.  
  5263. function commentsbar_ff_LoadLocalFile(filename, cache)
  5264. {
  5265.     try {
  5266.         var file;
  5267.         var imgurl;
  5268.         if (cache == true)
  5269.         {
  5270.             var cache_file_name = hex_md5(filename);
  5271.             imgurl = filename.replace(/^(.+\/)[^\/]+$/, "$1");
  5272.             filename = filename.replace(/.+\/(.+)$/, "$1");
  5273.             //temp
  5274.             var cache_path = commentsbar_ff_get_cache_path();
  5275.             file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  5276.             file.initWithPath(cache_path);
  5277.             file.append(cache_file_name);
  5278.         }
  5279.         else
  5280.         {
  5281.             file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  5282.             file.initWithPath(filename);
  5283.         }
  5284.  
  5285.         //load
  5286.         var data = '';
  5287.         if (file.exists())
  5288.         {
  5289.             var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
  5290.                     .createInstance(Components.interfaces.nsIFileInputStream);
  5291.             istream.init(file, 0x1, 0, 0);
  5292.             var binstream = Components.classes['@mozilla.org/binaryinputstream;1']
  5293.                     .createInstance(Components.interfaces.nsIBinaryInputStream);
  5294.             binstream.setInputStream(istream);
  5295.             data = binstream.readBytes(file.fileSize);
  5296.  
  5297.             binstream.close();
  5298.             istream.close();
  5299.         }
  5300.  
  5301.         var pos = 0;
  5302.         var start = 0;
  5303.         var end = 0;
  5304.         var img;
  5305.         var re;
  5306.         var url_to_img = commentsbar_ff_get_cache_path() + '/';
  5307.         while (pos < data.length && data.indexOf(' img', pos) != -1)
  5308.         {
  5309.             start = data.indexOf(' img', pos) + 6;
  5310.             end = data.indexOf('"', start);
  5311.             end2 = xmltext.indexOf("'", start);
  5312.             if (end == -1) end = end2;
  5313.             if (end2 < end) end = end2;
  5314.             if (end == -1) break;
  5315.             pos = end + 1;
  5316.             if (start == end) continue;
  5317.             img = data.substring(start, end);
  5318.             if (!img || img.toLowerCase().indexOf('.bmp') == -1) continue;
  5319.  
  5320.             re = new RegExp(' img="' + img + '"');
  5321.             //,"i");
  5322.             //        img=hex_md5(img.replace(/\.bmp$/i,'.png'));
  5323.             img = hex_md5(img);
  5324.             data = data.replace(re, ' img="file://' + url_to_img + img + '"');
  5325.         }
  5326.  
  5327.         pos = 0;
  5328.         while (pos < data.length && data.indexOf(' image', pos) != -1)
  5329.         {
  5330.             start = data.indexOf(' image', pos) + 8;
  5331.             end = data.indexOf('"', start);
  5332.             end2 = xmltext.indexOf("'", start);
  5333.             if (end == -1) end = end2;
  5334.             if (end2 < end) end = end2;
  5335.             if (end == -1) break;
  5336.             pos = end + 1;
  5337.             if (start == end) continue;
  5338.             img = data.substring(start, end);
  5339.             if (!img || img.toLowerCase().indexOf('.bmp') == -1) continue;
  5340.  
  5341.             re = new RegExp(' image="' + img + '"');
  5342.             //,"i");
  5343.             //       img=hex_md5(img.replace(/\.bmp$/i,'.png'));
  5344.             img = hex_md5(img);
  5345.             data = data.replace(re, ' image="file://' + url_to_img + img + '"');
  5346.         }
  5347.  
  5348.         pos = 0;
  5349.         while (pos < data.length && data.indexOf(' hot_image', pos) != -1)
  5350.         {
  5351.             start = data.indexOf(' hot_image', pos) + 12;
  5352.             end = data.indexOf('"', start);
  5353.             end2 = xmltext.indexOf("'", start);
  5354.             if (end == -1) end = end2;
  5355.             if (end2 < end) end = end2;
  5356.             if (end == -1) break;
  5357.             pos = end + 1;
  5358.             if (start == end) continue;
  5359.             img = data.substring(start, end);
  5360.             if (!img || img.toLowerCase().indexOf('.bmp') == -1) continue;
  5361.  
  5362.             re = new RegExp(' hot_image="' + img + '"');
  5363.             //,"i");
  5364.             //       img=hex_md5(img.replace(/\.bmp$/i,'.png'));
  5365.             img = hex_md5(img);
  5366.             data = data.replace(re, ' hot_image="file://' + url_to_img + img + '"');
  5367.         }
  5368.         return data;
  5369.  
  5370.     } catch(e) {
  5371.         if (debugmode) cbLog(e);
  5372.     }
  5373. }
  5374.  
  5375. function imgLoadListener(channel, img)
  5376. {
  5377.     this.mCountRead = 0;
  5378.     this.mChannel = channel;
  5379.     this.img = img;
  5380. }
  5381.  
  5382. imgLoadListener.prototype = {
  5383.     mCountRead : null,
  5384.     mChannel : null,
  5385.     mBytes : Array(),
  5386.     mStream : null,
  5387.     img : null,
  5388.  
  5389. // nsIRequestObserver
  5390.     onStartRequest : function (aRequest, aContext) {
  5391.         this.mStream = Components.classes['@mozilla.org/binaryinputstream;1'].createInstance(Components.interfaces.nsIBinaryInputStream);
  5392.     },
  5393.  
  5394.     onStopRequest : function (aRequest, aContext, aStatusCode) {
  5395.         try {
  5396.             var httpChannel = this.mChannel.QueryInterface(Components.interfaces.nsIHttpChannel);
  5397.             if (httpChannel && Components.isSuccessCode(aStatusCode) && this.mCountRead > 0 && httpChannel.requestSucceeded)
  5398.             {
  5399.                 commentsbar_ff_SaveLocalFile(this.mBytes, this.img, true);
  5400.             }
  5401.         } catch(e) {
  5402.             if (debugmode) cbLog(e);
  5403.         }
  5404.         this.mChannel = null;
  5405.     },
  5406.  
  5407.     onDataAvailable : function (aRequest, aContext, aInputStream, aOffset, aCount) {
  5408.         this.mStream.setInputStream(aInputStream);
  5409.         var chunk = this.mStream.readBytes(aCount);
  5410.         this.mBytes = this.mBytes + chunk;
  5411.         this.mCountRead += aCount;
  5412.     },
  5413.  
  5414.     onRedirect : function (aHttpChannel, aNewChannel) {
  5415.         this.mChannel = aNewChannel;
  5416.     },
  5417.  
  5418.     onProgress : function (aRequest, aContext, aProgress, aProgressMax) {
  5419.     },
  5420.  
  5421.  
  5422.  
  5423.  
  5424.     onStatus : function (aRequest, aContext, aStatus, aStatusArg) {
  5425.     }
  5426. }
  5427.  
  5428. function commentsbar_ff_get_cache_path()
  5429. {
  5430.     try {
  5431.         var file = Components.classes["@mozilla.org/file/directory_service;1"]
  5432.                 .getService(Components.interfaces.nsIProperties)
  5433.                 .get("TmpD", Components.interfaces.nsIFile);
  5434.         file.append('FFToolbar_Cache');
  5435.         return file.path;
  5436.     } catch(e) {
  5437.         if (debugmode) cbLog(e);
  5438.     }
  5439. }
  5440.  
  5441.  
  5442. ///////////////////////////////////////////////// 
  5443.  
  5444. //function commentsbar_ff_Highlight_aux_undo (win, word, colour)
  5445. //{
  5446. //    var f;
  5447. //    for (f = 0; f < win.frames.length; f++)
  5448. //  {
  5449. //        win.frames[f].document.body.innerHTML = win.frames[f].document.body.innerHTML.replace(/<layer id=\"toolbar\-highlight\"[^>]*>([^<]*)<\/layer>/gi, '$1');
  5450. //        commentsbar_ff_Highlight_aux_undo (win.frames[f], word, colour);
  5451. //    }
  5452. //}
  5453. var currentButtonId="";
  5454.  
  5455. var Widgets = new Array();
  5456.  
  5457. function CWidget(_name, _prop)
  5458.     {
  5459.     var name = _name;
  5460.     var isDraggged = false;
  5461.     var iLastCurPosX=0, iLastCurPosY=0;
  5462.     var prop = _prop;
  5463.     
  5464.     for(p in prop)
  5465.         {
  5466.         if (commentsbar_ff_load_pref(_name + "_" + p, "0") == "0")
  5467.             {
  5468.             commentsbar_ff_pref(_name + "_" + p, prop[p]);    
  5469.             }
  5470.         }
  5471.     if (currentButtonId!="")
  5472.         {
  5473.         var mmm = document.getElementById(currentButtonId);
  5474.         var m2 = document.getBoxObjectFor(mmm);
  5475.         var xx = m2.x;
  5476.         var height2 = m2.screenY - m2.y - window.screenY;
  5477.         var yy = m2.y + m2.height + height2;
  5478.         commentsbar_ff_pref(name + "_screenx", xx);
  5479.         commentsbar_ff_pref(name + "_screeny", yy);
  5480.         }
  5481.     else
  5482.         {
  5483.         if (prop.button != undefined)
  5484.             {
  5485.             var mmm = document.getElementById(prop.button);
  5486.             var m2 = document.getBoxObjectFor(mmm);
  5487.             var xx = m2.x;
  5488.             var height2 = m2.screenY - m2.y - window.screenY;
  5489.             var yy = m2.y + m2.height + height2;
  5490.             commentsbar_ff_pref(name + "_screenx", xx);
  5491.             commentsbar_ff_pref(name + "_screeny", yy);
  5492.             }
  5493.         else
  5494.             {
  5495.             commentsbar_ff_pref(name + "_screenx", prop.x);
  5496.             commentsbar_ff_pref(name + "_screeny", prop.y);
  5497.             }
  5498.         }
  5499.     commentsbar_ff_pref(name + "_width", prop.width);
  5500.     commentsbar_ff_pref(name + "_height", prop.height);
  5501.     commentsbar_ff_pref(name + "_widgetpath", prop.widgetpath);
  5502.     commentsbar_ff_pref(name + "_type", 1);
  5503.     commentsbar_ff_pref(name + "_scroll", 1);
  5504.     commentsbar_ff_pref(name + "_src", "chrome://commentsbar_ff/content/" + prop.url);
  5505.     commentsbar_ff_pref(name + "_caption", prop.caption);
  5506.       
  5507.     var wnd = window.openDialog('chrome://commentsbar_ff/content/bubble.xul', '', 'resizable,alwaysRaised,dependent=yes,titlebar=no');
  5508.     //return;
  5509.     wnd.window.name = _name;
  5510.     wnd.window.mainwindow = window;
  5511.     wnd.window.tool = this;
  5512.     
  5513.     this.close = function() 
  5514.         {
  5515.         for(i=0; i<Widgets.length; i++)
  5516.             {
  5517.             Widgets.splice(i,1);
  5518.             }
  5519.         wnd.close();
  5520.         }
  5521.     
  5522.     this.getProperty = function(_name, defval)
  5523.     {
  5524.         _name = name + "_" + _name;
  5525.             try {
  5526.                 var val = commentsbar_ff_getPref(_name);
  5527.                 if (val == null) 
  5528.                     if (_name == 'uniqid')
  5529.                     {
  5530.                                val = Math.round(Math.random()*1000000000000);
  5531.                         alert(val);
  5532.                         commentsbar_ff_pref(_name, val);
  5533.                         return val;
  5534.                     
  5535.                     } else
  5536.                         return defval;
  5537.                 return val;
  5538.             } catch(e) {
  5539.                 if (debugmode) cbLog(e);
  5540.                 return defval;
  5541.             }
  5542.     }
  5543.     this.setProperty = function(_name, val)
  5544.     {
  5545.             try {
  5546.                    commentsbar_ff_pref(name + "_" + _name, val);
  5547.                 return "OK";
  5548.             } catch(e) {
  5549.                 if (debugmode) cbLog(e);
  5550.                 return "Error";
  5551.             }
  5552.     }    
  5553.     this.getWindow = function(){
  5554.         return wnd;
  5555.     }
  5556.     this.resize = function (width, height) {
  5557.         wnd.resizeTo(width, height);
  5558.        }
  5559.     this.getSize = function() {
  5560.             return Array(wnd.outerWidth, wnd.outerHeight);
  5561.         }
  5562.  
  5563.     this.unCaptureMouse = function(ev){
  5564.         isDraggged = false;
  5565.         wnd.removeEventListener("mousemove", this.mouseMove, false);
  5566.     }
  5567.     this.captureMouse = function(ev){
  5568.         wnd.addEventListener("mousemove", this.mouseMove, false);
  5569.         wnd.addEventListener("mouseup", this.unCaptureMouse, false);
  5570.         iLastCurPosX = ev.screenX - wnd.screenX;
  5571.         iLastCurPosY = ev.screenY - wnd.screenY;
  5572.         isDraggged = true;    
  5573.     }
  5574.     this.mouseMove = function(ev){
  5575.          try{
  5576.              if (isDraggged)
  5577.              wnd.moveTo((ev.screenX-iLastCurPosX), 
  5578.                 (ev.screenY-iLastCurPosY));    
  5579.          }
  5580.          catch(e){if (debugmode) cbLog(e);}
  5581.     }
  5582. }
  5583.  
  5584.  
  5585. function commentsbar_ff_widget(name, url, prop)
  5586.     {
  5587.     
  5588.  
  5589.     prop = prop.replace(/\,$/gi,"");
  5590.     prop = prop.replace(/\"/gi,"\\\"");
  5591.     prop = prop.replace(/\|\|/gi,"\"");
  5592.     
  5593.  
  5594.     var val = eval("({"+prop+"});");
  5595.     
  5596.     val["url"] = url;
  5597.     try
  5598.         {
  5599.         for (i = 0; i<Widgets.length; i++)
  5600.             if (Widgets[i] == name) return false;
  5601.         Widgets.push(name);
  5602.         new CWidget(name, val);        
  5603.         } 
  5604.     catch(e)
  5605.         {
  5606.         alert(e)
  5607.         //if (debugmode) cbLog(e);
  5608.         }
  5609.     }
  5610.